index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import toInteger from "../_lib/toInteger/index.js";
  2. import getISOWeekYear from "../getISOWeekYear/index.js";
  3. import setISOWeekYear from "../setISOWeekYear/index.js";
  4. import requiredArgs from "../_lib/requiredArgs/index.js";
  5. /**
  6. * @name addISOWeekYears
  7. * @category ISO Week-Numbering Year Helpers
  8. * @summary Add the specified number of ISO week-numbering years to the given date.
  9. *
  10. * @description
  11. * Add the specified number of ISO week-numbering years to the given date.
  12. *
  13. * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
  14. *
  15. * ### v2.0.0 breaking changes:
  16. *
  17. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  18. *
  19. * - The function was renamed from `addISOYears` to `addISOWeekYears`.
  20. * "ISO week year" is short for [ISO week-numbering year](https://en.wikipedia.org/wiki/ISO_week_date).
  21. * This change makes the name consistent with
  22. * locale-dependent week-numbering year helpers, e.g., `addWeekYears`.
  23. *
  24. * @param {Date|Number} date - the date to be changed
  25. * @param {Number} amount - the amount of ISO week-numbering years to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
  26. * @returns {Date} the new date with the ISO week-numbering years added
  27. * @throws {TypeError} 2 arguments required
  28. *
  29. * @example
  30. * // Add 5 ISO week-numbering years to 2 July 2010:
  31. * const result = addISOWeekYears(new Date(2010, 6, 2), 5)
  32. * //=> Fri Jun 26 2015 00:00:00
  33. */
  34. export default function addISOWeekYears(dirtyDate, dirtyAmount) {
  35. requiredArgs(2, arguments);
  36. var amount = toInteger(dirtyAmount);
  37. return setISOWeekYear(dirtyDate, getISOWeekYear(dirtyDate) + amount);
  38. }