date_functions.ts 385 B

12345678910
  1. // function that receives two hours in hh:mm format and compares as a spaceship operator
  2. export function compareHours(h1: string, h2: string): number {
  3. const [h1h, h1m] = h1.split(":").map(Number);
  4. const [h2h, h2m] = h2.split(":").map(Number);
  5. if (h1h > h2h) return 1;
  6. if (h1h < h2h) return -1;
  7. if (h1m > h2m) return 1;
  8. if (h1m < h2m) return -1;
  9. return 0;
  10. }