index.js 1.0 KB

123456789101112131415161718192021222324252627
  1. import toInteger from "../_lib/toInteger/index.js";
  2. import addMonths from "../addMonths/index.js";
  3. import requiredArgs from "../_lib/requiredArgs/index.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. * @param {Date|Number} date - the date to be changed
  13. * @param {Number} amount - the amount of quarters to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
  14. * @returns {Date} the new date with the quarters added
  15. * @throws {TypeError} 2 arguments required
  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 default function addQuarters(dirtyDate, dirtyAmount) {
  23. requiredArgs(2, arguments);
  24. var amount = toInteger(dirtyAmount);
  25. var months = amount * 3;
  26. return addMonths(dirtyDate, months);
  27. }