index.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import differenceInMonths from "../differenceInMonths/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name differenceInQuarters
  5. * @category Quarter Helpers
  6. * @summary Get the number of full quarters between the given dates.
  7. *
  8. * @description
  9. * Get the number of full quarters between the given dates.
  10. *
  11. * ### v2.0.0 breaking changes:
  12. *
  13. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  14. *
  15. * @param {Date|Number} dateLeft - the later date
  16. * @param {Date|Number} dateRight - the earlier date
  17. * @returns {Number} the number of full quarters
  18. * @throws {TypeError} 2 arguments required
  19. *
  20. * @example
  21. * // How many full quarters are between 31 December 2013 and 2 July 2014?
  22. * var result = differenceInQuarters(new Date(2014, 6, 2), new Date(2013, 11, 31))
  23. * //=> 2
  24. */
  25. export default function differenceInQuarters(dirtyDateLeft, dirtyDateRight) {
  26. requiredArgs(2, arguments);
  27. var diff = differenceInMonths(dirtyDateLeft, dirtyDateRight) / 3;
  28. return diff > 0 ? Math.floor(diff) : Math.ceil(diff);
  29. }