date_functions.js 408 B

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