←back to thread

1045 points janpio | 4 comments | | HN request time: 0s | source
Show context
NelsonMinar ◴[] No.45676467[source]
Be sure to see the team's whole list of Cursed Knowledge. https://immich.app/cursed-knowledge
replies(6): >>45676661 #>>45677766 #>>45677816 #>>45678252 #>>45679167 #>>45680193 #
1. kyle-rb ◴[] No.45678252[source]
> JavaScript date objects are 1 indexed for years and days, but 0 indexed for months.

I don't disagree that months should be 1-indexed, but I would not make that assumption solely based on days/years being 1-indexed, since 0-indexing those would be psychotic.

replies(2): >>45678546 #>>45678812 #
2. watermelon0 ◴[] No.45678546[source]
Why so? Months in written form also start with 1, same as days/years, so it would make sense to match all of them.

For example, the first day of the first month of the first year is 1.1.1 AD (at least for Gregorian calendar), so we could just go with 0-indexed 0.0.0 AD.

3. kaoD ◴[] No.45678812[source]
The only reason I can think of to 0-index months is so you can do monthName[date.getMonth()] instead of monthName[date.getMonth() - 1].

I don't think adding counterintuitive behavior to your data to save a "- 1" here and there is a good idea, but I guess this is just legacy from the ancient times.

replies(1): >>45679173 #
4. oblio ◴[] No.45679173[source]
That would have a better solution in a date.getCurrentMonth(), in my opinion.