isThisHour.mjs 907 B

123456789101112131415161718192021222324252627282930
  1. import { constructNow } from "./constructNow.mjs";
  2. import { isSameHour } from "./isSameHour.mjs";
  3. /**
  4. * @name isThisHour
  5. * @category Hour Helpers
  6. * @summary Is the given date in the same hour as the current date?
  7. * @pure false
  8. *
  9. * @description
  10. * Is the given date in the same hour as the current date?
  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 date - The date to check
  15. *
  16. * @returns The date is in this hour
  17. *
  18. * @example
  19. * // If now is 25 September 2014 18:30:15.500,
  20. * // is 25 September 2014 18:00:00 in this hour?
  21. * const result = isThisHour(new Date(2014, 8, 25, 18))
  22. * //=> true
  23. */
  24. export function isThisHour(date) {
  25. return isSameHour(date, constructNow(date));
  26. }
  27. // Fallback for modularized imports:
  28. export default isThisHour;