UNPKG

1.55 kBTypeScriptView Raw
1import type { ContextOptions, DateArg, Duration } from "./types.js";
2/**
3 * The {@link add} function options.
4 */
5export interface AddOptions<DateType extends Date = Date>
6 extends ContextOptions<DateType> {}
7/**
8 * @name add
9 * @category Common Helpers
10 * @summary Add the specified years, months, weeks, days, hours, minutes, and seconds to the given date.
11 *
12 * @description
13 * Add the specified years, months, weeks, days, hours, minutes, and seconds to the given date.
14 *
15 * @typeParam DateType - The `Date` type the function operates on. Gets inferred from passed arguments. Allows using extensions like [`UTCDate`](https://github.com/date-fns/utc).
16 * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
17 *
18 * @param date - The date to be changed
19 * @param duration - The object with years, months, weeks, days, hours, minutes, and seconds to be added.
20 * @param options - An object with options
21 *
22 * @returns The new date with the seconds added
23 *
24 * @example
25 * // Add the following duration to 1 September 2014, 10:19:50
26 * const result = add(new Date(2014, 8, 1, 10, 19, 50), {
27 * years: 2,
28 * months: 9,
29 * weeks: 1,
30 * days: 7,
31 * hours: 5,
32 * minutes: 9,
33 * seconds: 30,
34 * })
35 * //=> Thu Jun 15 2017 15:29:20
36 */
37export declare function add<
38 DateType extends Date,
39 ResultDate extends Date = DateType,
40>(
41 date: DateArg<DateType>,
42 duration: Duration,
43 options?: AddOptions<ResultDate> | undefined,
44): ResultDate;