index.js 740 B

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