index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import startOfDay from "../startOfDay/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name isSameDay
  5. * @category Day Helpers
  6. * @summary Are the given dates in the same day (and year and month)?
  7. *
  8. * @description
  9. * Are the given dates in the same day (and year and month)?
  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 day (and year and month)
  14. * @throws {TypeError} 2 arguments required
  15. *
  16. * @example
  17. * // Are 4 September 06:00:00 and 4 September 18:00:00 in the same day?
  18. * const result = isSameDay(new Date(2014, 8, 4, 6, 0), new Date(2014, 8, 4, 18, 0))
  19. * //=> true
  20. *
  21. * @example
  22. * // Are 4 September and 4 October in the same day?
  23. * const result = isSameDay(new Date(2014, 8, 4), new Date(2014, 9, 4))
  24. * //=> false
  25. *
  26. * @example
  27. * // Are 4 September, 2014 and 4 September, 2015 in the same day?
  28. * const result = isSameDay(new Date(2014, 8, 4), new Date(2015, 8, 4))
  29. * //=> false
  30. */
  31. export default function isSameDay(dirtyDateLeft, dirtyDateRight) {
  32. requiredArgs(2, arguments);
  33. var dateLeftStartOfDay = startOfDay(dirtyDateLeft);
  34. var dateRightStartOfDay = startOfDay(dirtyDateRight);
  35. return dateLeftStartOfDay.getTime() === dateRightStartOfDay.getTime();
  36. }