index.js 1.1 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?
  7. *
  8. * @description
  9. * Are the given dates in the same hour?
  10. *
  11. * ### v2.0.0 breaking changes:
  12. *
  13. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  14. *
  15. * @param {Date|Number} dateLeft - the first date to check
  16. * @param {Date|Number} dateRight - the second date to check
  17. * @returns {Boolean} the dates are in the same hour
  18. * @throws {TypeError} 2 arguments required
  19. *
  20. * @example
  21. * // Are 4 September 2014 06:00:00 and 4 September 06:30:00 in the same hour?
  22. * var result = isSameHour(new Date(2014, 8, 4, 6, 0), new Date(2014, 8, 4, 6, 30))
  23. * //=> true
  24. */
  25. export default function isSameHour(dirtyDateLeft, dirtyDateRight) {
  26. requiredArgs(2, arguments);
  27. var dateLeftStartOfHour = startOfHour(dirtyDateLeft);
  28. var dateRightStartOfHour = startOfHour(dirtyDateRight);
  29. return dateLeftStartOfHour.getTime() === dateRightStartOfHour.getTime();
  30. }