index.js 1.2 KB

12345678910111213141516171819202122232425262728
  1. import addISOWeekYears from "../addISOWeekYears/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. import toInteger from "../_lib/toInteger/index.js";
  4. /**
  5. * @name subISOWeekYears
  6. * @category ISO Week-Numbering Year Helpers
  7. * @summary Subtract the specified number of ISO week-numbering years from the given date.
  8. *
  9. * @description
  10. * Subtract the specified number of ISO week-numbering years from the given date.
  11. *
  12. * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
  13. *
  14. * @param {Date|Number} date - the date to be changed
  15. * @param {Number} amount - the amount of ISO week-numbering years to be subtracted. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
  16. * @returns {Date} the new date with the ISO week-numbering years subtracted
  17. * @throws {TypeError} 2 arguments required
  18. *
  19. * @example
  20. * // Subtract 5 ISO week-numbering years from 1 September 2014:
  21. * const result = subISOWeekYears(new Date(2014, 8, 1), 5)
  22. * //=> Mon Aug 31 2009 00:00:00
  23. */
  24. export default function subISOWeekYears(dirtyDate, dirtyAmount) {
  25. requiredArgs(2, arguments);
  26. var amount = toInteger(dirtyAmount);
  27. return addISOWeekYears(dirtyDate, -amount);
  28. }