addQuarters.js 896 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. exports.addQuarters = addQuarters;
  3. var _index = require("./addMonths.js");
  4. /**
  5. * @name addQuarters
  6. * @category Quarter Helpers
  7. * @summary Add the specified number of year quarters to the given date.
  8. *
  9. * @description
  10. * Add the specified number of year quarters 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 quarters to be added.
  16. *
  17. * @returns The new date with the quarters added
  18. *
  19. * @example
  20. * // Add 1 quarter to 1 September 2014:
  21. * const result = addQuarters(new Date(2014, 8, 1), 1)
  22. * //=> Mon Dec 01 2014 00:00:00
  23. */
  24. function addQuarters(date, amount) {
  25. const months = amount * 3;
  26. return (0, _index.addMonths)(date, months);
  27. }