index.js 1.7 KB

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