71

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

all 18 comments
sorted by: hot top controversial new old
[-] spartanatreyu@programming.dev 2 points 1 hour ago

Also: January is not always the 1st month, sometimes it is the 0th.

1/1/2026 can be both Jan 1st, and Feb 1st.

[-] litchralee@sh.itjust.works 14 points 5 hours ago

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.

[-] folekaule@lemmy.world 9 points 5 hours ago

Even better: two weeks with the same week number can exist in the same year.

[-] hallettj@leminal.space 3 points 4 hours ago

How is that? Do you mean that week 1 can occur twice? Or is there another issue?

IIUC you can have days at the start and the end of the year that are all in week 1, and those are two different weeks. But one of those would be, let's say, week 1 year 2025, and the other would be week 1 year 2026. According to the blog post if you have a week 1 at the end of a year the ISO year number for that week is the next year.

[-] folekaule@lemmy.world 6 points 3 hours ago

It only happens with ISO weeks. An example is 2006. Each of the weeks belong to different years (so 2005W52 and 2006W52 are different), but each can contain days from another year. So for example Sunday 2006-01-01 is part of week 52 of 2005. Week 1 starts on January 2. Then at the end of 2006 you have another week 52, but that week is actually part of 2006.

It's a bit of a cheeky thing to point out, because at no point is a day in two different weeks, and the week itself only belongs to one year. It's just that you can't assume that any given day belongs to the same year as the week it is in. That is: 2006-01-01 is in 2005W52 not 2006W01.

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.

[-] folekaule@lemmy.world 4 points 4 hours ago

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

[-] Skullgrid@lemmy.world 21 points 8 hours ago

fuck sake.

thanks for the heads up

[-] Pissmidget@lemmy.world 19 points 8 hours ago

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.

[-] bleistift2@sopuli.xyz 13 points 8 hours ago

If you think looking at Thursday seems like a random choice: It’s basically a majority vote among the days of the week. If Thursday is in the new year, then 4 days (Thu–Sun) are in the new year. If Thursday is in the old year, then 4 days are in the old year (Mon–Thu).

[-] ttayh@lemmy.zip 15 points 8 hours ago

The 1st day of the feek is not universal. I grew up with the week starting on sunday

[-] bleistift2@sopuli.xyz 12 points 8 hours ago

Yes, another thing in the neverending list of shit you have to learn at some point if you’re any kind of programmer.

Some people start their week on the wrong day.

[-] TehPers@beehaw.org 2 points 8 hours ago

Like ISO 8601. /s

[-] sergiu@lemmy.world 6 points 7 hours ago

Is this a thing outside the USA? It always bugs me when apps default to this. How does it make any sense for the week to start with the weekend?

[-] brisk@aussie.zone 4 points 5 hours ago

A string has two ends

[-] technohacker@programming.dev 2 points 5 hours ago

I've generally seen Sunday to be the start of the week here, my current headcanon for it is that Sunday and Saturday sort of book-end on both sides of the week, hence week-end_s_ plural

this post was submitted on 24 Mar 2026
71 points (100.0% liked)

Programming

26203 readers
418 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 2 years ago
MODERATORS