UNPKG

1.21 kBJavaScriptView Raw
1import { startOfISOWeekYear } from "./startOfISOWeekYear.mjs";
2
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 * @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).
14 *
15 * @param dateLeft - The first date to check
16 * @param dateRight - The second date to check
17 *
18 * @returns The dates are in the same ISO week-numbering year
19 *
20 * @example
21 * // Are 29 December 2003 and 2 January 2005 in the same ISO week-numbering year?
22 * const result = isSameISOWeekYear(new Date(2003, 11, 29), new Date(2005, 0, 2))
23 * //=> true
24 */
25export function isSameISOWeekYear(dateLeft, dateRight) {
26 const dateLeftStartOfYear = startOfISOWeekYear(dateLeft);
27 const dateRightStartOfYear = startOfISOWeekYear(dateRight);
28
29 return +dateLeftStartOfYear === +dateRightStartOfYear;
30}
31
32// Fallback for modularized imports:
33export default isSameISOWeekYear;