addHours.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { addMilliseconds } from "./addMilliseconds.js";
  2. import { millisecondsInHour } from "./constants.js";
  3. /**
  4. * The {@link addHours} function options.
  5. */
  6. /**
  7. * @name addHours
  8. * @category Hour Helpers
  9. * @summary Add the specified number of hours to the given date.
  10. *
  11. * @description
  12. * Add the specified number of hours to the given date.
  13. *
  14. * @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).
  15. * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
  16. *
  17. * @param date - The date to be changed
  18. * @param amount - The amount of hours to be added
  19. * @param options - An object with options
  20. *
  21. * @returns The new date with the hours added
  22. *
  23. * @example
  24. * // Add 2 hours to 10 July 2014 23:00:00:
  25. * const result = addHours(new Date(2014, 6, 10, 23, 0), 2)
  26. * //=> Fri Jul 11 2014 01:00:00
  27. */
  28. export function addHours(date, amount, options) {
  29. return addMilliseconds(date, amount * millisecondsInHour, options);
  30. }
  31. // Fallback for modularized imports:
  32. export default addHours;