addISOWeekYears.mjs 1.1 KB

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