index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import startOfISOWeekYear from "../startOfISOWeekYear/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name isSameISOWeekYear
  5. * @category ISO Week-Numbering Year Helpers
  6. * @summary Are the given dates in the same ISO week-numbering year?
  7. *
  8. * @description
  9. * Are the given dates in the same ISO week-numbering year?
  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 `isSameISOYear` to `isSameISOWeekYear`.
  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., `getWeekYear`.
  21. *
  22. * @param {Date|Number} dateLeft - the first date to check
  23. * @param {Date|Number} dateRight - the second date to check
  24. * @returns {Boolean} the dates are in the same ISO week-numbering year
  25. * @throws {TypeError} 2 arguments required
  26. *
  27. * @example
  28. * // Are 29 December 2003 and 2 January 2005 in the same ISO week-numbering year?
  29. * var result = isSameISOWeekYear(new Date(2003, 11, 29), new Date(2005, 0, 2))
  30. * //=> true
  31. */
  32. export default function isSameISOWeekYear(dirtyDateLeft, dirtyDateRight) {
  33. requiredArgs(2, arguments);
  34. var dateLeftStartOfYear = startOfISOWeekYear(dirtyDateLeft);
  35. var dateRightStartOfYear = startOfISOWeekYear(dirtyDateRight);
  36. return dateLeftStartOfYear.getTime() === dateRightStartOfYear.getTime();
  37. }