index.js 710 B

1234567891011121314151617181920212223242526
  1. var parse = require('../parse/index.js')
  2. /**
  3. * @category Second Helpers
  4. * @summary Set the seconds to the given date.
  5. *
  6. * @description
  7. * Set the seconds to the given date.
  8. *
  9. * @param {Date|String|Number} date - the date to be changed
  10. * @param {Number} seconds - the seconds of the new date
  11. * @returns {Date} the new date with the seconds setted
  12. *
  13. * @example
  14. * // Set 45 seconds to 1 September 2014 11:30:40:
  15. * var result = setSeconds(new Date(2014, 8, 1, 11, 30, 40), 45)
  16. * //=> Mon Sep 01 2014 11:30:45
  17. */
  18. function setSeconds (dirtyDate, dirtySeconds) {
  19. var date = parse(dirtyDate)
  20. var seconds = Number(dirtySeconds)
  21. date.setSeconds(seconds)
  22. return date
  23. }
  24. module.exports = setSeconds