index.js 932 B

12345678910111213141516171819202122232425262728
  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. * @param {Date|Number} date - the date to check
  16. * @returns {Boolean} the date is in this hour
  17. * @throws {TypeError} 1 argument required
  18. *
  19. * @example
  20. * // If now is 25 September 2014 18:30:15.500,
  21. * // is 25 September 2014 18:00:00 in this hour?
  22. * const result = isThisHour(new Date(2014, 8, 25, 18))
  23. * //=> true
  24. */
  25. export default function isThisHour(dirtyDate) {
  26. requiredArgs(1, arguments);
  27. return isSameHour(Date.now(), dirtyDate);
  28. }