From a2114079d0a2f2bb747a7efb1df9d7eebf99ff68 Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Mon, 17 Jan 2022 15:53:10 +0100 Subject: [PATCH] Fix getWeekNumber calculating week numbers wrong for Arabic and Hebrew calendars Closes #578 --- src/shared/dates.js | 4 ++-- src/shared/dates.spec.js | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/shared/dates.js b/src/shared/dates.js index bed9b4a2..8113d5e3 100644 --- a/src/shared/dates.js +++ b/src/shared/dates.js @@ -109,7 +109,7 @@ export function getWeekNumber(date, calendarType = CALENDAR_TYPES.ISO_8601) { ? CALENDAR_TYPES.US : CALENDAR_TYPES.ISO_8601 ); - const beginOfWeek = getBeginOfWeek(date, calendarTypeForWeekNumber); + const beginOfWeek = getBeginOfWeek(date, calendarType); let year = getYear(date) + 1; let dayInWeekOne; let beginOfFirstWeek; @@ -117,7 +117,7 @@ export function getWeekNumber(date, calendarType = CALENDAR_TYPES.ISO_8601) { // Look for the first week one that does not come after a given date do { dayInWeekOne = new Date(year, 0, calendarTypeForWeekNumber === CALENDAR_TYPES.ISO_8601 ? 4 : 1); - beginOfFirstWeek = getBeginOfWeek(dayInWeekOne, calendarTypeForWeekNumber); + beginOfFirstWeek = getBeginOfWeek(dayInWeekOne, calendarType); year -= 1; } while (date < beginOfFirstWeek); diff --git a/src/shared/dates.spec.js b/src/shared/dates.spec.js index 83652c46..0e22404b 100644 --- a/src/shared/dates.spec.js +++ b/src/shared/dates.spec.js @@ -221,9 +221,9 @@ describe('getWeekNumber', () => { }); it('returns proper week number for a sample year starting in week 1 (US)', () => { - const year = 2015; - const month = 11; - const startDate = 27; + const year = 2016; + const month = 0; + const startDate = 1; for (let currentWeek = 1; currentWeek <= 53; currentWeek += 1) { const weekOffset = (currentWeek - 1) * 7; @@ -264,7 +264,7 @@ describe('getWeekNumber', () => { }); it('returns proper week number for a sample week 1 (Arabic)', () => { - const year = 2018; + const year = 2022; const month = 0; const startDate = 1; @@ -293,7 +293,7 @@ describe('getWeekNumber', () => { }); it('returns proper week number for a sample week 52 (Arabic)', () => { - const year = 2016; + const year = 2020; const month = 11; const startDate = 26; @@ -307,7 +307,7 @@ describe('getWeekNumber', () => { }); it('returns proper week number for a sample week 53 (Arabic)', () => { - const year = 2015; + const year = 2019; const month = 11; const startDate = 28; @@ -321,7 +321,7 @@ describe('getWeekNumber', () => { }); it('returns proper week number for a sample week 1 (Hebrew)', () => { - const year = 2018; + const year = 2017; const month = 0; const startDate = 1; @@ -352,7 +352,7 @@ describe('getWeekNumber', () => { it('returns proper week number for a sample week 52 (Hebrew)', () => { const year = 2016; const month = 11; - const startDate = 26; + const startDate = 25; for (let currentDate = startDate; currentDate < startDate + 7; currentDate += 1) { const date = new Date(year, month, currentDate); @@ -364,7 +364,7 @@ describe('getWeekNumber', () => { }); it('returns proper week number for a sample week 53 (Hebrew)', () => { - const year = 2015; + const year = 2014; const month = 11; const startDate = 28;