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
[–] -1 points 5 months ago* (last edited 5 months ago) (5 children)

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

  • source
  • hideshow 5 child comments
  • [–] 2 points 5 months ago (4 children)

    but the first month is 0-indexed

    U mean “the months are zero indexed” and “the first month is 0”

  • source
  • parent
  • hideshow 4 child comments
  • [–] 0 points 5 months ago* (3 children)

    The first month is inputted with a 1 and exported as a 0.

    The first day is inputted with a 1 and exported as a 1.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 2 points 5 months ago (2 children)

    I understand that. Because the months are zero indexed. But it’s not just the first month that’s “0-indexed”. The list of months is zero indexed. Perhaps I’m arguing semantics - but was simply adding clarity for the reader.

    1st becomes 0, 2nd becomes 1, 3rd becomes 2

  • source
  • parent
  • hideshow 2 child comments