isSameISOWeekYear.js 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. exports.isSameISOWeekYear = isSameISOWeekYear;
  3. var _index = require("./startOfISOWeekYear.js");
  4. /**
  5. * @name isSameISOWeekYear
  6. * @category ISO Week-Numbering Year Helpers
  7. * @summary Are the given dates in the same ISO week-numbering year?
  8. *
  9. * @description
  10. * Are the given dates in the same ISO week-numbering year?
  11. *
  12. * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
  13. *
  14. * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
  15. *
  16. * @param dateLeft - The first date to check
  17. * @param dateRight - The second date to check
  18. *
  19. * @returns The dates are in the same ISO week-numbering year
  20. *
  21. * @example
  22. * // Are 29 December 2003 and 2 January 2005 in the same ISO week-numbering year?
  23. * const result = isSameISOWeekYear(new Date(2003, 11, 29), new Date(2005, 0, 2))
  24. * //=> true
  25. */
  26. function isSameISOWeekYear(dateLeft, dateRight) {
  27. const dateLeftStartOfYear = (0, _index.startOfISOWeekYear)(dateLeft);
  28. const dateRightStartOfYear = (0, _index.startOfISOWeekYear)(dateRight);
  29. return +dateLeftStartOfYear === +dateRightStartOfYear;
  30. }