1 | ;
|
2 | exports.addDays = addDays;
|
3 | var _index = require("./toDate.js");
|
4 | var _index2 = require("./constructFrom.js");
|
5 |
|
6 | /**
|
7 | * @name addDays
|
8 | * @category Day Helpers
|
9 | * @summary Add the specified number of days to the given date.
|
10 | *
|
11 | * @description
|
12 | * Add the specified number of days 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 | *
|
16 | * @param date - The date to be changed
|
17 | * @param amount - The amount of days to be added.
|
18 | *
|
19 | * @returns The new date with the days added
|
20 | *
|
21 | * @example
|
22 | * // Add 10 days to 1 September 2014:
|
23 | * const result = addDays(new Date(2014, 8, 1), 10)
|
24 | * //=> Thu Sep 11 2014 00:00:00
|
25 | */
|
26 | function addDays(date, amount) {
|
27 | const _date = (0, _index.toDate)(date);
|
28 | if (isNaN(amount)) return (0, _index2.constructFrom)(date, NaN);
|
29 | if (!amount) {
|
30 | // If 0 days, no-op to avoid changing times in the hour before end of DST
|
31 | return _date;
|
32 | }
|
33 | _date.setDate(_date.getDate() + amount);
|
34 | return _date;
|
35 | }
|