UNPKG

1.15 kBJavaScriptView Raw
1import { getISOWeekYear } from "./getISOWeekYear.mjs";
2import { setISOWeekYear } from "./setISOWeekYear.mjs";
3
4/**
5 * @name addISOWeekYears
6 * @category ISO Week-Numbering Year Helpers
7 * @summary Add the specified number of ISO week-numbering years to the given date.
8 *
9 * @description
10 * Add the specified number of ISO week-numbering years to the given date.
11 *
12 * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_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 ISO week-numbering years to be added.
18 *
19 * @returns The new date with the ISO week-numbering years added
20 *
21 * @example
22 * // Add 5 ISO week-numbering years to 2 July 2010:
23 * const result = addISOWeekYears(new Date(2010, 6, 2), 5)
24 * //=> Fri Jn 26 2015 00:00:00
25 */
26export function addISOWeekYears(date, amount) {
27 return setISOWeekYear(date, getISOWeekYear(date) + amount);
28}
29
30// Fallback for modularized imports:
31export default addISOWeekYears;