addQuarters.mjs 913 B

1234567891011121314151617181920212223242526272829
  1. import { addMonths } from "./addMonths.mjs";
  2. /**
  3. * @name addQuarters
  4. * @category Quarter Helpers
  5. * @summary Add the specified number of year quarters to the given date.
  6. *
  7. * @description
  8. * Add the specified number of year quarters 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 quarters to be added.
  14. *
  15. * @returns The new date with the quarters added
  16. *
  17. * @example
  18. * // Add 1 quarter to 1 September 2014:
  19. * const result = addQuarters(new Date(2014, 8, 1), 1)
  20. * //=> Mon Dec 01 2014 00:00:00
  21. */
  22. export function addQuarters(date, amount) {
  23. const months = amount * 3;
  24. return addMonths(date, months);
  25. }
  26. // Fallback for modularized imports:
  27. export default addQuarters;