UNPKG

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