addYears.js 1001 B

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