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:
Ajit Singh
2020-06-18 20:15:18 +05:30
committed by Andrew Kushnir
parent e36d5b201a
commit ef1fb6dee4
2 changed files with 17 additions and 1 deletions

View File

@ -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
}