index.js 776 B

1234567891011121314151617181920212223242526
  1. var addMilliseconds = require('../add_milliseconds/index.js')
  2. var MILLISECONDS_IN_HOUR = 3600000
  3. /**
  4. * @category Hour Helpers
  5. * @summary Add the specified number of hours to the given date.
  6. *
  7. * @description
  8. * Add the specified number of hours to the given date.
  9. *
  10. * @param {Date|String|Number} date - the date to be changed
  11. * @param {Number} amount - the amount of hours to be added
  12. * @returns {Date} the new date with the hours added
  13. *
  14. * @example
  15. * // Add 2 hours to 10 July 2014 23:00:00:
  16. * var result = addHours(new Date(2014, 6, 10, 23, 0), 2)
  17. * //=> Fri Jul 11 2014 01:00:00
  18. */
  19. function addHours (dirtyDate, dirtyAmount) {
  20. var amount = Number(dirtyAmount)
  21. return addMilliseconds(dirtyDate, amount * MILLISECONDS_IN_HOUR)
  22. }
  23. module.exports = addHours