UNPKG

1.67 kBTypeScriptView Raw
1import type { Duration } from "./types.js";
2/**
3 * @name add
4 * @category Common Helpers
5 * @summary Add the specified years, months, weeks, days, hours, minutes and seconds to the given date.
6 *
7 * @description
8 * Add the specified years, months, weeks, days, hours, minutes and seconds to the given date.
9 *
10 * @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).
11 *
12 * @param date - The date to be changed
13 * @param duration - The object with years, months, weeks, days, hours, minutes and seconds to be added.
14 *
15 * | Key | Description |
16 * |----------------|------------------------------------|
17 * | years | Amount of years to be added |
18 * | months | Amount of months to be added |
19 * | weeks | Amount of weeks to be added |
20 * | days | Amount of days to be added |
21 * | hours | Amount of hours to be added |
22 * | minutes | Amount of minutes to be added |
23 * | seconds | Amount of seconds to be added |
24 *
25 * All values default to 0
26 *
27 * @returns The new date with the seconds added
28 *
29 * @example
30 * // Add the following duration to 1 September 2014, 10:19:50
31 * const result = add(new Date(2014, 8, 1, 10, 19, 50), {
32 * years: 2,
33 * months: 9,
34 * weeks: 1,
35 * days: 7,
36 * hours: 5,\\-7
37 * minutes: 9,
38 * seconds: 30,
39 * })
40 * //=> Thu Jun 15 2017 15:29:20
41 */
42export declare function add<DateType extends Date>(
43 date: DateType | number | string,
44 duration: Duration,
45): DateType;