index.js 818 B

12345678910111213141516171819202122232425
  1. var parse = require('../parse/index.js')
  2. /**
  3. * @category Millisecond Helpers
  4. * @summary Add the specified number of milliseconds to the given date.
  5. *
  6. * @description
  7. * Add the specified number of milliseconds to the given date.
  8. *
  9. * @param {Date|String|Number} date - the date to be changed
  10. * @param {Number} amount - the amount of milliseconds to be added
  11. * @returns {Date} the new date with the milliseconds added
  12. *
  13. * @example
  14. * // Add 750 milliseconds to 10 July 2014 12:45:30.000:
  15. * var result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
  16. * //=> Thu Jul 10 2014 12:45:30.750
  17. */
  18. function addMilliseconds (dirtyDate, dirtyAmount) {
  19. var timestamp = parse(dirtyDate).getTime()
  20. var amount = Number(dirtyAmount)
  21. return new Date(timestamp + amount)
  22. }
  23. module.exports = addMilliseconds