addMonths.d.cts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import type { ContextOptions, DateArg } from "./types.js";
  2. /**
  3. * The {@link addMonths} function options.
  4. */
  5. export interface AddMonthsOptions<DateType extends Date = Date>
  6. extends ContextOptions<DateType> {}
  7. /**
  8. * @name addMonths
  9. * @category Month Helpers
  10. * @summary Add the specified number of months to the given date.
  11. *
  12. * @description
  13. * Add the specified number of months to the given date.
  14. *
  15. * @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).
  16. * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
  17. *
  18. * @param date - The date to be changed
  19. * @param amount - The amount of months to be added.
  20. * @param options - The options object
  21. *
  22. * @returns The new date with the months added
  23. *
  24. * @example
  25. * // Add 5 months to 1 September 2014:
  26. * const result = addMonths(new Date(2014, 8, 1), 5)
  27. * //=> Sun Feb 01 2015 00:00:00
  28. *
  29. * // Add one month to 30 January 2023:
  30. * const result = addMonths(new Date(2023, 0, 30), 1)
  31. * //=> Tue Feb 28 2023 00:00:00
  32. */
  33. export declare function addMonths<
  34. DateType extends Date,
  35. ResultDate extends Date = DateType,
  36. >(
  37. date: DateArg<DateType>,
  38. amount: number,
  39. options?: AddMonthsOptions<ResultDate> | undefined,
  40. ): ResultDate;