question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

weeksInWeekYear returns wrong results

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
icambroncommented, Dec 5, 2021

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()

0reactions
icambroncommented, Dec 9, 2021

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found