index.js 674 B

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