isSameMinute.mjs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { startOfMinute } from "./startOfMinute.mjs";
  2. /**
  3. * @name isSameMinute
  4. * @category Minute Helpers
  5. * @summary Are the given dates in the same minute (and hour and day)?
  6. *
  7. * @description
  8. * Are the given dates in the same minute (and hour and day)?
  9. *
  10. * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
  11. *
  12. * @param dateLeft - The first date to check
  13. * @param dateRight - The second date to check
  14. *
  15. * @returns The dates are in the same minute (and hour and day)
  16. *
  17. * @example
  18. * // Are 4 September 2014 06:30:00 and 4 September 2014 06:30:15 in the same minute?
  19. * const result = isSameMinute(
  20. * new Date(2014, 8, 4, 6, 30),
  21. * new Date(2014, 8, 4, 6, 30, 15)
  22. * )
  23. * //=> true
  24. *
  25. * @example
  26. * // Are 4 September 2014 06:30:00 and 5 September 2014 06:30:00 in the same minute?
  27. * const result = isSameMinute(
  28. * new Date(2014, 8, 4, 6, 30),
  29. * new Date(2014, 8, 5, 6, 30)
  30. * )
  31. * //=> false
  32. */
  33. export function isSameMinute(dateLeft, dateRight) {
  34. const dateLeftStartOfMinute = startOfMinute(dateLeft);
  35. const dateRightStartOfMinute = startOfMinute(dateRight);
  36. return +dateLeftStartOfMinute === +dateRightStartOfMinute;
  37. }
  38. // Fallback for modularized imports:
  39. export default isSameMinute;