weeksInWeekYear returns wrong results
See original GitHub issueDescribe the bug The year 2021 has 52 ISO Weeks (compare with Google Calendar), but luxon returns 53 for the year 2021. This must be wrong, because Week 52 goes from 27.12.21 to 02.01.22. After this the first week of 2022 must follow, cause it always contains 4th january (see ISO 8601 for reference)
To Reproduce
console.log(DateTime.fromISO("2021").weeksInWeekYear) // returns 53
Actual vs Expected behavior Should return right number of weeks.
Workaround
function weeksInYear(year) {
return DateTime.fromISO(year + "-12-28").weekNumber;
}
Desktop (please complete the following information):
- OS: [e.g. iOS] Windows
- Browser [e.g. Chrome 84, safari 14.0] Chrome 96
- Luxon version [e.g. 1.25.0] 2.2.1
- Your timezone [e.g. “America/New_York”] Europe/Berlin
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
java - Calendar get year returns wrong result - Stack Overflow
I suspect that the calendar is trying to use the current day-of-week (it's Thursday today) in the first week of 2016.
Read more >luxon 3.1.1 | Documentation
Returns whether the DateTime is valid. Invalid DateTimes occur when: The DateTime was created from invalid calendar information, such as the 13th month...
Read more >GetWeekOfYear() method returns incorrect result - MSDN
My website needs to work out the week number of a date to create a date code (Week Week Year Year). The date...
Read more >Solved: Show current time on separate rows for each time zone
The objective here is to be able to show the current time for each time zone by putting the time zones one-by-one into...
Read more >UNPKG - @types/luxon
This allows you to round up the result if it fits inside the threshold. ... 774, * Returns true if this DateTime is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think I can guess the confusion. The “ISO” in “fromISO” doesn’t refer to the ISO week calendar; it refers to the ISO 8601 string format. When parsing a just alone year, that refers to the Gregorian year. Does that help?
[Edit] Try
fromObject({weekYear: 2021}).weeksInWeekYear()
DateTimes are specific instants in time.
fromISO
returns such an instant. That instant is in the 2021 Gregorian year but not the 2021 ISO year. Thus weeksInWeekYear is returning the number of weeks in the iso week year your datetime is actually in