addHours.js 920 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. exports.addHours = addHours;
  3. var _index = require("./addMilliseconds.js");
  4. var _index2 = require("./constants.js");
  5. /**
  6. * @name addHours
  7. * @category Hour Helpers
  8. * @summary Add the specified number of hours to the given date.
  9. *
  10. * @description
  11. * Add the specified number of hours to the given date.
  12. *
  13. * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
  14. *
  15. * @param date - The date to be changed
  16. * @param amount - The amount of hours to be added.
  17. *
  18. * @returns The new date with the hours added
  19. *
  20. * @example
  21. * // Add 2 hours to 10 July 2014 23:00:00:
  22. * const result = addHours(new Date(2014, 6, 10, 23, 0), 2)
  23. * //=> Fri Jul 11 2014 01:00:00
  24. */
  25. function addHours(date, amount) {
  26. return (0, _index.addMilliseconds)(date, amount * _index2.millisecondsInHour);
  27. }