index.js 901 B

1234567891011121314151617181920212223242526272829
  1. var parse = require('../parse/index.js')
  2. /**
  3. * @category Millisecond Helpers
  4. * @summary Get the number of milliseconds between the given dates.
  5. *
  6. * @description
  7. * Get the number of milliseconds between the given dates.
  8. *
  9. * @param {Date|String|Number} dateLeft - the later date
  10. * @param {Date|String|Number} dateRight - the earlier date
  11. * @returns {Number} the number of milliseconds
  12. *
  13. * @example
  14. * // How many milliseconds are between
  15. * // 2 July 2014 12:30:20.600 and 2 July 2014 12:30:21.700?
  16. * var result = differenceInMilliseconds(
  17. * new Date(2014, 6, 2, 12, 30, 21, 700),
  18. * new Date(2014, 6, 2, 12, 30, 20, 600)
  19. * )
  20. * //=> 1100
  21. */
  22. function differenceInMilliseconds (dirtyDateLeft, dirtyDateRight) {
  23. var dateLeft = parse(dirtyDateLeft)
  24. var dateRight = parse(dirtyDateRight)
  25. return dateLeft.getTime() - dateRight.getTime()
  26. }
  27. module.exports = differenceInMilliseconds