isThisHour.js 913 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { constructNow } from "./constructNow.js";
  2. import { isSameHour } from "./isSameHour.js";
  3. import { toDate } from "./toDate.js";
  4. /**
  5. * The {@link isThisHour} function options.
  6. */
  7. /**
  8. * @name isThisHour
  9. * @category Hour Helpers
  10. * @summary Is the given date in the same hour as the current date?
  11. * @pure false
  12. *
  13. * @description
  14. * Is the given date in the same hour as the current date?
  15. *
  16. * @param date - The date to check
  17. * @param options - An object with options
  18. *
  19. * @returns The date is in this hour
  20. *
  21. * @example
  22. * // If now is 25 September 2014 18:30:15.500,
  23. * // is 25 September 2014 18:00:00 in this hour?
  24. * const result = isThisHour(new Date(2014, 8, 25, 18))
  25. * //=> true
  26. */
  27. export function isThisHour(date, options) {
  28. return isSameHour(
  29. toDate(date, options?.in),
  30. constructNow(options?.in || date),
  31. );
  32. }
  33. // Fallback for modularized imports:
  34. export default isThisHour;