differenceInQuarters.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. exports.differenceInQuarters = differenceInQuarters;
  3. var _index = require("./_lib/getRoundingMethod.js");
  4. var _index2 = require("./differenceInMonths.js");
  5. /**
  6. * The {@link differenceInQuarters} function options.
  7. */
  8. /**
  9. * @name differenceInQuarters
  10. * @category Quarter Helpers
  11. * @summary Get the number of quarters between the given dates.
  12. *
  13. * @description
  14. * Get the number of quarters between the given dates.
  15. *
  16. * @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).
  17. *
  18. * @param dateLeft - The later date
  19. * @param dateRight - The earlier date
  20. * @param options - An object with options.
  21. *
  22. * @returns The number of full quarters
  23. *
  24. * @example
  25. * // How many full quarters are between 31 December 2013 and 2 July 2014?
  26. * const result = differenceInQuarters(new Date(2014, 6, 2), new Date(2013, 11, 31))
  27. * //=> 2
  28. */
  29. function differenceInQuarters(dateLeft, dateRight, options) {
  30. const diff = (0, _index2.differenceInMonths)(dateLeft, dateRight) / 3;
  31. return (0, _index.getRoundingMethod)(options?.roundingMethod)(diff);
  32. }