isSameHour.cjs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. exports.isSameHour = isSameHour;
  3. var _index = require("./_lib/normalizeDates.cjs");
  4. var _index2 = require("./startOfHour.cjs");
  5. /**
  6. * The {@link isSameHour} function options.
  7. */
  8. /**
  9. * @name isSameHour
  10. * @category Hour Helpers
  11. * @summary Are the given dates in the same hour (and same day)?
  12. *
  13. * @description
  14. * Are the given dates in the same hour (and same day)?
  15. *
  16. * @param dateLeft - The first date to check
  17. * @param dateRight - The second date to check
  18. * @param options - An object with options
  19. *
  20. * @returns The dates are in the same hour (and same day)
  21. *
  22. * @example
  23. * // Are 4 September 2014 06:00:00 and 4 September 06:30:00 in the same hour?
  24. * const result = isSameHour(new Date(2014, 8, 4, 6, 0), new Date(2014, 8, 4, 6, 30))
  25. * //=> true
  26. *
  27. * @example
  28. * // Are 4 September 2014 06:00:00 and 5 September 06:00:00 in the same hour?
  29. * const result = isSameHour(new Date(2014, 8, 4, 6, 0), new Date(2014, 8, 5, 6, 0))
  30. * //=> false
  31. */
  32. function isSameHour(dateLeft, dateRight, options) {
  33. const [dateLeft_, dateRight_] = (0, _index.normalizeDates)(
  34. options?.in,
  35. dateLeft,
  36. dateRight,
  37. );
  38. return (
  39. +(0, _index2.startOfHour)(dateLeft_) ===
  40. +(0, _index2.startOfHour)(dateRight_)
  41. );
  42. }