Skip to content

Commit

Permalink
Fix getWeekNumber calculating week numbers wrong for Arabic and Hebre…
Browse files Browse the repository at this point in the history
…w calendars

Closes wojtekmaj#578
  • Loading branch information
wojtekmaj authored and felixmosh committed Jan 24, 2022
1 parent 6528245 commit a211407
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/shared/dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ 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;

// 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);

Expand Down
18 changes: 9 additions & 9 deletions src/shared/dates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand Down

0 comments on commit a211407

Please sign in to comment.