The other day at work I stumbled upon this bug and thought it was worth to write a blog post about. Spoiler: It has nothing to do with timezones!
TLDR: According to ISO standard 8601 (which is what Python’s date.isocalendar().week uses for example), the first week of the year is the week with the first Thursday of the year. So sometimes the first few days of January belong to the last week of previous year, and sometimes the last few days of December belong to the first week of next year :D
Obligatory links:
Falsehoods that programmers think about dates and times: https://infiniteundo.com/post/25326999628/falsehoods-programmers-believe-about-time
Tom Scott descends into time and timezone madness: https://www.youtube.com/watch?v=-5wpm-gesOY
I’ve personally never worked with ISO 8601 directly, and quite frankly prefer how RFC 3339 simply doesn’t deal with weeks at all.
That video is a classic. It’s exactly why I put “it has nothing to do with timezones” as subtitle for the post :) That was my first guess when I encountered the bug, before I realized it was about the ISO weeks.
And in the end of the post I also added a list of falsehoods, different from your link tho: https://gist.github.com/timvisee/fcda9bbdff88d45cc9061606b4b923ca
fuck sake.
thanks for the heads up
Even better: two weeks with the same week number can exist in the same year.
Fuck, I just wrote an app to help HR process data and I had to, without using Ai, define the first week of the year to match that ISO spec. Week 53 was a fun one but I now have to cover two weeks with the same number.
Yep, but the year of week will be different for each.
Use a date library. Life is too short to make your own. The new Temporal library in JavaScript is quite good.
It’s written in C++ lol
As all good libraries are 😎
Week numbers can also vary by country. Not always, but sometimes, as we’re not all in agreement on what constitutes the first week of the year.
Something most people in international organisations and teams get to find out the hard way at least once.
I hate working with date/time.
I kid you not, i just had to fix a date time issue around formatting lol. Like minutes after I wrote i hate it lol.
Similarly, developers have many misconceptions about addresses: https://www.mjt.me.uk/posts/falsehoods-programmers-believe-about-addresses/
So nobody talks about leap seconds? 😅
deleted by creator
Also: January is not always the 1st month, sometimes it is the 0th.
1/1/2026 can be both Jan 1st, and Feb 1st.
For the downvoters, try it in your browser’s terminal:
let test = new Date("1-1-2026"); console.log(`Year: ${test.getFullYear()}, Month: ${test.getMonth()}, Day: ${test.getDate()}`); // Prints -> Year: 2026, Month: 0, Day: 1 // --- --- --- --- --- --- --- --- // test.getFullYear() returns the year, but test.getYear() only returns the number of years since 1900 // test.getMonth() returns the month, but the first month is 0-indexed // test.getDate() returns the day, 1-indexed, but test.getDay() returns the current day right now and not the day of the date object





