addHours.mjs 951 B

1234567891011121314151617181920212223242526272829
  1. import { addMilliseconds } from "./addMilliseconds.mjs";
  2. import { millisecondsInHour } from "./constants.mjs";
  3. /**
  4. * @name addHours
  5. * @category Hour Helpers
  6. * @summary Add the specified number of hours to the given date.
  7. *
  8. * @description
  9. * Add the specified number of hours to the given date.
  10. *
  11. * @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).
  12. *
  13. * @param date - The date to be changed
  14. * @param amount - The amount of hours to be added.
  15. *
  16. * @returns The new date with the hours added
  17. *
  18. * @example
  19. * // Add 2 hours to 10 July 2014 23:00:00:
  20. * const result = addHours(new Date(2014, 6, 10, 23, 0), 2)
  21. * //=> Fri Jul 11 2014 01:00:00
  22. */
  23. export function addHours(date, amount) {
  24. return addMilliseconds(date, amount * millisecondsInHour);
  25. }
  26. // Fallback for modularized imports:
  27. export default addHours;