83

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

you are viewing a single comment's thread
view the rest of the comments
[-] folekaule@lemmy.world 9 points 8 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.

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

Programming

26203 readers
500 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