index.js 1.4 KB

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