Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formatUTCWeekNumberISO and formatWeekNumberISO return incorrect results at edge of the year #120

Open
28raining opened this issue Aug 20, 2023 · 4 comments

Comments

@28raining
Copy link

28raining commented Aug 20, 2023

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

@28raining
Copy link
Author

The issue may also exist in formatUTCFullYearISO and formatFullYearISO

@28raining
Copy link
Author

Created PR: #121

@Fil
Copy link
Member

Fil commented Aug 21, 2023

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

@28raining
Copy link
Author

That's really interesting! Glad you know your dates.
Let me look again at the original issue and confirm it's unrelated to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants