fix(common): date pipe gives wrong week number (#37632)
Date pipe is giving wrong week number when used with the date format 'w'. If first week(according to Iso) has some days in previous year Fixes #33961 PR Close #37632
This commit is contained in:

committed by
Andrew Kushnir

parent
e36d5b201a
commit
ef1fb6dee4
@ -382,8 +382,10 @@ function weekGetter(size: number, monthBased = false): DateFormatter {
|
||||
const today = date.getDate();
|
||||
result = 1 + Math.floor((today + nbDaysBefore1stDayOfMonth) / 7);
|
||||
} else {
|
||||
const firstThurs = getFirstThursdayOfYear(date.getFullYear());
|
||||
const thisThurs = getThursdayThisWeek(date);
|
||||
// Some days of a year are part of next year according to ISO 8601.
|
||||
// Compute the firstThurs from the year of this week's Thursday
|
||||
const firstThurs = getFirstThursdayOfYear(thisThurs.getFullYear());
|
||||
const diff = thisThurs.getTime() - firstThurs.getTime();
|
||||
result = 1 + Math.round(diff / 6.048e8); // 6.048e8 ms per week
|
||||
}
|
||||
|
Reference in New Issue
Block a user