index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import getISOWeekYear from "../getISOWeekYear/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name differenceInCalendarISOWeekYears
  5. * @category ISO Week-Numbering Year Helpers
  6. * @summary Get the number of calendar ISO week-numbering years between the given dates.
  7. *
  8. * @description
  9. * Get the number of calendar ISO week-numbering years between the given dates.
  10. *
  11. * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
  12. *
  13. * ### v2.0.0 breaking changes:
  14. *
  15. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  16. *
  17. * - The function was renamed from `differenceInCalendarISOYears` to `differenceInCalendarISOWeekYears`.
  18. * "ISO week year" is short for [ISO week-numbering year](https://en.wikipedia.org/wiki/ISO_week_date).
  19. * This change makes the name consistent with
  20. * locale-dependent week-numbering year helpers, e.g., `addWeekYears`.
  21. *
  22. * @param {Date|Number} dateLeft - the later date
  23. * @param {Date|Number} dateRight - the earlier date
  24. * @returns {Number} the number of calendar ISO week-numbering years
  25. * @throws {TypeError} 2 arguments required
  26. *
  27. * @example
  28. * // How many calendar ISO week-numbering years are 1 January 2010 and 1 January 2012?
  29. * const result = differenceInCalendarISOWeekYears(
  30. * new Date(2012, 0, 1),
  31. * new Date(2010, 0, 1)
  32. * )
  33. * //=> 2
  34. */
  35. export default function differenceInCalendarISOWeekYears(dirtyDateLeft, dirtyDateRight) {
  36. requiredArgs(2, arguments);
  37. return getISOWeekYear(dirtyDateLeft) - getISOWeekYear(dirtyDateRight);
  38. }