index.js 899 B

12345678910111213141516171819202122232425262728
  1. var differenceInMilliseconds = require('../difference_in_milliseconds/index.js')
  2. /**
  3. * @category Second Helpers
  4. * @summary Get the number of seconds between the given dates.
  5. *
  6. * @description
  7. * Get the number of seconds 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 seconds
  12. *
  13. * @example
  14. * // How many seconds are between
  15. * // 2 July 2014 12:30:07.999 and 2 July 2014 12:30:20.000?
  16. * var result = differenceInSeconds(
  17. * new Date(2014, 6, 2, 12, 30, 20, 0),
  18. * new Date(2014, 6, 2, 12, 30, 7, 999)
  19. * )
  20. * //=> 12
  21. */
  22. function differenceInSeconds (dirtyDateLeft, dirtyDateRight) {
  23. var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / 1000
  24. return diff > 0 ? Math.floor(diff) : Math.ceil(diff)
  25. }
  26. module.exports = differenceInSeconds