index.js 868 B

1234567891011121314151617181920212223242526272829
  1. var startOfHour = require('../start_of_hour/index.js')
  2. /**
  3. * @category Hour Helpers
  4. * @summary Are the given dates in the same hour?
  5. *
  6. * @description
  7. * Are the given dates in the same hour?
  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 hour
  12. *
  13. * @example
  14. * // Are 4 September 2014 06:00:00 and 4 September 06:30:00 in the same hour?
  15. * var result = isSameHour(
  16. * new Date(2014, 8, 4, 6, 0),
  17. * new Date(2014, 8, 4, 6, 30)
  18. * )
  19. * //=> true
  20. */
  21. function isSameHour (dirtyDateLeft, dirtyDateRight) {
  22. var dateLeftStartOfHour = startOfHour(dirtyDateLeft)
  23. var dateRightStartOfHour = startOfHour(dirtyDateRight)
  24. return dateLeftStartOfHour.getTime() === dateRightStartOfHour.getTime()
  25. }
  26. module.exports = isSameHour