Closed nightskylark closed 3 years ago
Thanks for filing the issue and your detailed debugging. If you (or someone) can (a) confirm your logic matches UTS#35 and (b) submit a PR, it will be accepted. Thanks
(a) confirm your logic matches UTS#35
I'm sure that "my logic" matches the standard because the "w" pattern means "Week of Year (numeric)" (See here). All days of the single week should have the same Week of Year index. I don't think it is described in the specification, because it's the basic logic that doesn't have to be explained.
Perfect! 👍 Awesome you've already created a draft PR.
Steps to reproduce in Node.js: (npm install globalize cldr-data)
Case 1.
It returns
1
but theweekData.firstDay
is0
in 'en' locale andweekData.minDays
is1
, so the result should be2
.Case 2.
It returns
0
but theweekData.firstDay
is1
in 'de' locale andweekData.minDays
is4
, so the result should be1
.Solution Here is a mistake in calculation: https://github.com/globalizejs/globalize/blob/master/src/date/format.js#L151 The previously calculated value of the
value
variable is the count of days in the first week in year that belongs to the previous year. In 'en' locale in 2021 it will be 5 (27-31 of December 2020). ThedateDayOfYear( date )
returns a distance between the first day of year and the current day. For the 3th of January it will be2
. So our calculation is(5 (27-31 of December) + 2 (2-3 of January)) / 7
. But there is no 1st of January here! What we need is to add+1
to the formula like this:dateDayOfYear( date ) + 1 + value ) / 7