isSameDay.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. exports.isSameDay = isSameDay;
  3. var _index = require("./startOfDay.js");
  4. /**
  5. * @name isSameDay
  6. * @category Day Helpers
  7. * @summary Are the given dates in the same day (and year and month)?
  8. *
  9. * @description
  10. * Are the given dates in the same day (and year and month)?
  11. *
  12. * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
  13. *
  14. * @param dateLeft - The first date to check
  15. * @param dateRight - The second date to check
  16. * @returns The dates are in the same day (and year and month)
  17. *
  18. * @example
  19. * // Are 4 September 06:00:00 and 4 September 18:00:00 in the same day?
  20. * const result = isSameDay(new Date(2014, 8, 4, 6, 0), new Date(2014, 8, 4, 18, 0))
  21. * //=> true
  22. *
  23. * @example
  24. * // Are 4 September and 4 October in the same day?
  25. * const result = isSameDay(new Date(2014, 8, 4), new Date(2014, 9, 4))
  26. * //=> false
  27. *
  28. * @example
  29. * // Are 4 September, 2014 and 4 September, 2015 in the same day?
  30. * const result = isSameDay(new Date(2014, 8, 4), new Date(2015, 8, 4))
  31. * //=> false
  32. */
  33. function isSameDay(dateLeft, dateRight) {
  34. const dateLeftStartOfDay = (0, _index.startOfDay)(dateLeft);
  35. const dateRightStartOfDay = (0, _index.startOfDay)(dateRight);
  36. return +dateLeftStartOfDay === +dateRightStartOfDay;
  37. }