index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import isSameHour from "../isSameHour/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  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. * > ⚠️ Please note that this function is not present in the FP submodule as
  13. * > it uses `Date.now()` internally hence impure and can't be safely curried.
  14. *
  15. * ### v2.0.0 breaking changes:
  16. *
  17. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  18. *
  19. * @param {Date|Number} date - the date to check
  20. * @returns {Boolean} the date is in this hour
  21. * @throws {TypeError} 1 argument required
  22. *
  23. * @example
  24. * // If now is 25 September 2014 18:30:15.500,
  25. * // is 25 September 2014 18:00:00 in this hour?
  26. * var result = isThisHour(new Date(2014, 8, 25, 18))
  27. * //=> true
  28. */
  29. export default function isThisHour(dirtyDate) {
  30. requiredArgs(1, arguments);
  31. return isSameHour(Date.now(), dirtyDate);
  32. }