addYears.mjs 850 B

12345678910111213141516171819202122232425262728
  1. import { addMonths } from "./addMonths.mjs";
  2. /**
  3. * @name addYears
  4. * @category Year Helpers
  5. * @summary Add the specified number of years to the given date.
  6. *
  7. * @description
  8. * Add the specified number of years to the given date.
  9. *
  10. * @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).
  11. *
  12. * @param date - The date to be changed
  13. * @param amount - The amount of years to be added.
  14. *
  15. * @returns The new date with the years added
  16. *
  17. * @example
  18. * // Add 5 years to 1 September 2014:
  19. * const result = addYears(new Date(2014, 8, 1), 5)
  20. * //=> Sun Sep 01 2019 00:00:00
  21. */
  22. export function addYears(date, amount) {
  23. return addMonths(date, amount * 12);
  24. }
  25. // Fallback for modularized imports:
  26. export default addYears;