index.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = addISOWeekYears;
  6. var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
  7. var _index2 = _interopRequireDefault(require("../getISOWeekYear/index.js"));
  8. var _index3 = _interopRequireDefault(require("../setISOWeekYear/index.js"));
  9. var _index4 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. /**
  12. * @name addISOWeekYears
  13. * @category ISO Week-Numbering Year Helpers
  14. * @summary Add the specified number of ISO week-numbering years to the given date.
  15. *
  16. * @description
  17. * Add the specified number of ISO week-numbering years to the given date.
  18. *
  19. * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
  20. *
  21. * ### v2.0.0 breaking changes:
  22. *
  23. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  24. *
  25. * - The function was renamed from `addISOYears` to `addISOWeekYears`.
  26. * "ISO week year" is short for [ISO week-numbering year](https://en.wikipedia.org/wiki/ISO_week_date).
  27. * This change makes the name consistent with
  28. * locale-dependent week-numbering year helpers, e.g., `addWeekYears`.
  29. *
  30. * @param {Date|Number} date - the date to be changed
  31. * @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`.
  32. * @returns {Date} the new date with the ISO week-numbering years added
  33. * @throws {TypeError} 2 arguments required
  34. *
  35. * @example
  36. * // Add 5 ISO week-numbering years to 2 July 2010:
  37. * const result = addISOWeekYears(new Date(2010, 6, 2), 5)
  38. * //=> Fri Jun 26 2015 00:00:00
  39. */
  40. function addISOWeekYears(dirtyDate, dirtyAmount) {
  41. (0, _index4.default)(2, arguments);
  42. var amount = (0, _index.default)(dirtyAmount);
  43. return (0, _index3.default)(dirtyDate, (0, _index2.default)(dirtyDate) + amount);
  44. }
  45. module.exports = exports.default;