4 ms·
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 co
by kaoD 1y ago
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.
- oblio 1y agoThat would have a better solution in a date.getCurrentMonth(), in my opinion.
- kaoD 1y agoTemporal[0] is coming which solves many many many issues with JS Date, 1-based months[1] included! Can't wait for it to be stable and widely available, it's just too good. > month values start at 1, which is different from legacy Date where months are represented by zero-based indices (0 to 11) [0] https://tc39.es/proposal-temporal/docs/ https://tc39.es/proposal-temporal/docs/ [1] https://tc39.es/proposal-temporal/docs/plaindate.html#month https://tc39.es/proposal-temporal/docs/plaindate.html#month
- its_brass 1y agoA [StackOverflow thread](https://stackoverflow.com/a/41992352 https://stackoverflow.com/a/41992352) about this interface says it was introduced by Java way back in 1995, and copied by the first JavaScript implementation.
- zahlman 1y ago(We don't have Markdown formatting here, BTW. But thanks for the heads up, and welcome to YC.)