isSameMinute.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. exports.isSameMinute = isSameMinute;
  3. var _index = require("./startOfMinute.js");
  4. /**
  5. * @name isSameMinute
  6. * @category Minute Helpers
  7. * @summary Are the given dates in the same minute (and hour and day)?
  8. *
  9. * @description
  10. * Are the given dates in the same minute (and hour and day)?
  11. *
  12. * @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).
  13. *
  14. * @param dateLeft - The first date to check
  15. * @param dateRight - The second date to check
  16. *
  17. * @returns The dates are in the same minute (and hour and day)
  18. *
  19. * @example
  20. * // Are 4 September 2014 06:30:00 and 4 September 2014 06:30:15 in the same minute?
  21. * const result = isSameMinute(
  22. * new Date(2014, 8, 4, 6, 30),
  23. * new Date(2014, 8, 4, 6, 30, 15)
  24. * )
  25. * //=> true
  26. *
  27. * @example
  28. * // Are 4 September 2014 06:30:00 and 5 September 2014 06:30:00 in the same minute?
  29. * const result = isSameMinute(
  30. * new Date(2014, 8, 4, 6, 30),
  31. * new Date(2014, 8, 5, 6, 30)
  32. * )
  33. * //=> false
  34. */
  35. function isSameMinute(dateLeft, dateRight) {
  36. const dateLeftStartOfMinute = (0, _index.startOfMinute)(dateLeft);
  37. const dateRightStartOfMinute = (0, _index.startOfMinute)(dateRight);
  38. return +dateLeftStartOfMinute === +dateRightStartOfMinute;
  39. }