formatUTCWeekNumberISO and formatWeekNumberISO return incorrect results at edge of the year
These functions work by counting how many Thursdays have occurred up to this date
function formatUTCWeekNumberISO(d, p) { d = UTCdISO(d); return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2); }
Unfortunately the argument d is re-assigned and can cause the year to roll over, so that utcYear(d) returns a different year because UTC is in a different timezone
Codepen: https://codepen.io/28raining/pen/VwqYaKL?editors=1111
Using a separate variable avoids this
function formatUTCWeekNumberISO(d, p) { var dUTC = UTCdISO(d); return pad(utcThursday.count(utcYear(d), dUTC ) + (utcYear(d).getUTCDay() === 4), p, 2); }
The issue may also exist in formatUTCFullYearISO and formatFullYearISO
Created PR: https://github.com/d3/d3-time-format/pull/121
ISO weeks do rollover, and the results shown by this codepen seem correct to me. The two last days of 2019 (Dec 30 and 31) belong to Week 01, see for example http://www.whatweekisit.org/calendar-2019.html
That's really interesting! Glad you know your dates. Let me look again at the original issue and confirm it's unrelated to this.