index.js 1.2 KB

12345678910111213141516171819202122232425262728
  1. import differenceInMonths from "../differenceInMonths/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. import { getRoundingMethod } from "../_lib/roundingMethods/index.js";
  4. /**
  5. * @name differenceInQuarters
  6. * @category Quarter Helpers
  7. * @summary Get the number of quarters between the given dates.
  8. *
  9. * @description
  10. * Get the number of quarters between the given dates.
  11. *
  12. * @param {Date|Number} dateLeft - the later date
  13. * @param {Date|Number} dateRight - the earlier date
  14. * @param {Object} [options] - an object with options.
  15. * @param {String} [options.roundingMethod='trunc'] - a rounding method (`ceil`, `floor`, `round` or `trunc`)
  16. * @returns {Number} the number of full quarters
  17. * @throws {TypeError} 2 arguments required
  18. *
  19. * @example
  20. * // How many full quarters are between 31 December 2013 and 2 July 2014?
  21. * const result = differenceInQuarters(new Date(2014, 6, 2), new Date(2013, 11, 31))
  22. * //=> 2
  23. */
  24. export default function differenceInQuarters(dateLeft, dateRight, options) {
  25. requiredArgs(2, arguments);
  26. var diff = differenceInMonths(dateLeft, dateRight) / 3;
  27. return getRoundingMethod(options === null || options === void 0 ? void 0 : options.roundingMethod)(diff);
  28. }