index.js 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. import startOfHour from "../startOfHour/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name isSameHour
  5. * @category Hour Helpers
  6. * @summary Are the given dates in the same hour (and same day)?
  7. *
  8. * @description
  9. * Are the given dates in the same hour (and same day)?
  10. *
  11. * @param {Date|Number} dateLeft - the first date to check
  12. * @param {Date|Number} dateRight - the second date to check
  13. * @returns {Boolean} the dates are in the same hour (and same day)
  14. * @throws {TypeError} 2 arguments required
  15. *
  16. * @example
  17. * // Are 4 September 2014 06:00:00 and 4 September 06:30:00 in the same hour?
  18. * const result = isSameHour(new Date(2014, 8, 4, 6, 0), new Date(2014, 8, 4, 6, 30))
  19. * //=> true
  20. *
  21. * @example
  22. * // Are 4 September 2014 06:00:00 and 5 September 06:00:00 in the same hour?
  23. * const result = isSameHour(new Date(2014, 8, 4, 6, 0), new Date(2014, 8, 5, 6, 0))
  24. * //=> false
  25. */
  26. export default function isSameHour(dirtyDateLeft, dirtyDateRight) {
  27. requiredArgs(2, arguments);
  28. var dateLeftStartOfHour = startOfHour(dirtyDateLeft);
  29. var dateRightStartOfHour = startOfHour(dirtyDateRight);
  30. return dateLeftStartOfHour.getTime() === dateRightStartOfHour.getTime();
  31. }