addYears.js 830 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. exports.addYears = addYears;
  3. var _index = require("./addMonths.js");
  4. /**
  5. * @name addYears
  6. * @category Year Helpers
  7. * @summary Add the specified number of years to the given date.
  8. *
  9. * @description
  10. * Add the specified number of years to the given date.
  11. *
  12. * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
  13. *
  14. * @param date - The date to be changed
  15. * @param amount - The amount of years to be added.
  16. *
  17. * @returns The new date with the years added
  18. *
  19. * @example
  20. * // Add 5 years to 1 September 2014:
  21. * const result = addYears(new Date(2014, 8, 1), 5)
  22. * //=> Sun Sep 01 2019 00:00:00
  23. */
  24. function addYears(date, amount) {
  25. return (0, _index.addMonths)(date, amount * 12);
  26. }