index.js 1.3 KB

1234567891011121314151617181920212223242526272829
  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. * @param {Date|Number} date - the date to be changed
  16. * @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`.
  17. * @returns {Date} the new date with the ISO week-numbering years added
  18. * @throws {TypeError} 2 arguments required
  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 Jun 26 2015 00:00:00
  24. */
  25. export default function addISOWeekYears(dirtyDate, dirtyAmount) {
  26. requiredArgs(2, arguments);
  27. var amount = toInteger(dirtyAmount);
  28. return setISOWeekYear(dirtyDate, getISOWeekYear(dirtyDate) + amount);
  29. }