index.js 847 B

1234567891011121314151617181920212223242526272829
  1. var startOfDay = require('../start_of_day/index.js')
  2. /**
  3. * @category Day Helpers
  4. * @summary Are the given dates in the same day?
  5. *
  6. * @description
  7. * Are the given dates in the same day?
  8. *
  9. * @param {Date|String|Number} dateLeft - the first date to check
  10. * @param {Date|String|Number} dateRight - the second date to check
  11. * @returns {Boolean} the dates are in the same day
  12. *
  13. * @example
  14. * // Are 4 September 06:00:00 and 4 September 18:00:00 in the same day?
  15. * var result = isSameDay(
  16. * new Date(2014, 8, 4, 6, 0),
  17. * new Date(2014, 8, 4, 18, 0)
  18. * )
  19. * //=> true
  20. */
  21. function isSameDay (dirtyDateLeft, dirtyDateRight) {
  22. var dateLeftStartOfDay = startOfDay(dirtyDateLeft)
  23. var dateRightStartOfDay = startOfDay(dirtyDateRight)
  24. return dateLeftStartOfDay.getTime() === dateRightStartOfDay.getTime()
  25. }
  26. module.exports = isSameDay