index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = differenceInCalendarYears;
  6. var _index = _interopRequireDefault(require("../toDate/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 differenceInCalendarYears
  11. * @category Year Helpers
  12. * @summary Get the number of calendar years between the given dates.
  13. *
  14. * @description
  15. * Get the number of calendar years 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 calendar years
  24. * @throws {TypeError} 2 arguments required
  25. *
  26. * @example
  27. * // How many calendar years are between 31 December 2013 and 11 February 2015?
  28. * const result = differenceInCalendarYears(
  29. * new Date(2015, 1, 11),
  30. * new Date(2013, 11, 31)
  31. * )
  32. * //=> 2
  33. */
  34. function differenceInCalendarYears(dirtyDateLeft, dirtyDateRight) {
  35. (0, _index2.default)(2, arguments);
  36. var dateLeft = (0, _index.default)(dirtyDateLeft);
  37. var dateRight = (0, _index.default)(dirtyDateRight);
  38. return dateLeft.getFullYear() - dateRight.getFullYear();
  39. }
  40. module.exports = exports.default;