January 1st is not always on the first week of the year (www.jpvalencia.com)
from null4141@programming.dev to programming@programming.dev on 24 Mar 17:43
https://programming.dev/post/47720263

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

#programming

threaded - newest

bleistift2@sopuli.xyz on 24 Mar 17:48 next collapse

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 on 24 Mar 18:04 collapse

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

bleistift2@sopuli.xyz on 24 Mar 18:08 next collapse

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 on 24 Mar 18:19 collapse

Like ISO 8601. /s

sergiu@lemmy.world on 24 Mar 19:03 collapse

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?

bleistift2@sopuli.xyz on 24 Mar 19:14 collapse

God rested on the seventh day, but Sabbath is on Saturday. Tadaa, week starts on Sunday.

Skullgrid@lemmy.world on 24 Mar 17:54 next collapse

fuck sake.

thanks for the heads up

Pissmidget@lemmy.world on 24 Mar 17:58 next collapse

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.

[deleted] on 24 Mar 18:08 collapse
.