index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import toInteger from "../_lib/toInteger/index.js";
  2. import addISOWeekYears from "../addISOWeekYears/index.js";
  3. import requiredArgs from "../_lib/requiredArgs/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. * ### v2.0.0 breaking changes:
  15. *
  16. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  17. *
  18. * - The function was renamed from `subISOYears` to `subISOWeekYears`.
  19. * "ISO week year" is short for [ISO week-numbering year](https://en.wikipedia.org/wiki/ISO_week_date).
  20. * This change makes the name consistent with
  21. * locale-dependent week-numbering year helpers, e.g., `setWeekYear`.
  22. *
  23. * @param {Date|Number} date - the date to be changed
  24. * @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`.
  25. * @returns {Date} the new date with the ISO week-numbering years subtracted
  26. * @throws {TypeError} 2 arguments required
  27. *
  28. * @example
  29. * // Subtract 5 ISO week-numbering years from 1 September 2014:
  30. * const result = subISOWeekYears(new Date(2014, 8, 1), 5)
  31. * //=> Mon Aug 31 2009 00:00:00
  32. */
  33. export default function subISOWeekYears(dirtyDate, dirtyAmount) {
  34. requiredArgs(2, arguments);
  35. var amount = toInteger(dirtyAmount);
  36. return addISOWeekYears(dirtyDate, -amount);
  37. }