index.js 933 B

123456789101112131415161718192021222324252627282930
  1. var startOfSecond = require('../start_of_second/index.js')
  2. /**
  3. * @category Second Helpers
  4. * @summary Are the given dates in the same second?
  5. *
  6. * @description
  7. * Are the given dates in the same second?
  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 second
  12. *
  13. * @example
  14. * // Are 4 September 2014 06:30:15.000 and 4 September 2014 06:30.15.500
  15. * // in the same second?
  16. * var result = isSameSecond(
  17. * new Date(2014, 8, 4, 6, 30, 15),
  18. * new Date(2014, 8, 4, 6, 30, 15, 500)
  19. * )
  20. * //=> true
  21. */
  22. function isSameSecond (dirtyDateLeft, dirtyDateRight) {
  23. var dateLeftStartOfSecond = startOfSecond(dirtyDateLeft)
  24. var dateRightStartOfSecond = startOfSecond(dirtyDateRight)
  25. return dateLeftStartOfSecond.getTime() === dateRightStartOfSecond.getTime()
  26. }
  27. module.exports = isSameSecond