4 ms·
This one isn't mentioned: > d Thu Feb 27 2020 17:05:28 GMT-0600 (Central Standard Time) > d.getMonth() 1 I'm as fond of zero-indexing as anyone, but t
by jessaustin 7y ago
This one isn't mentioned:
> d
Thu Feb 27 2020 17:05:28 GMT-0600 (Central Standard Time)
> d.getMonth()
1
I'm as fond of zero-indexing as anyone, but this is ridiculous.
- bcheung 7y agoAgreed. This is probably my #1 annoyance.
- cesarb 7y agoEven worse, it's not even internally consistent: while the month of the year starts at 0, the day of the month starts at 1. This is one of the worst API design mistakes of Java, and Javascript blindly copied it. At least the newer Java APIs (the java.time ones) fixed that: the month starts at 1 with the newer APIs (when not using the enum). But I don't have much hope of Javascript copying the new and better API.
- nobleach 7y agoI definitely don't think Brendan "blindly" copied it. At the time, Sun was pushing Java hard. Netscape wanted in on that. So they delivered an edict to "make it look like Java". We can all say, "well I would have pushed back". But it's hard to say what would have happened. He'd have probably been taken off the project. Hindsight really is 20/20.
- gruez 7y ago>At the time, Sun was pushing Java hard. Netscape wanted in on that. [...] He'd have probably been taken off the project. Can you elaborate on this? Was netscape owned/funded by Sun?
- tyingq 7y agoThere was a partnership. The CNet article is still around. https://www.cnet.com/news/netscape-and-sun-unveil-javascript/ https://www.cnet.com/news/netscape-and-sun-unveil-javascript...
- baddox 7y agoThe reason there's an "exception" for days is that the numbers are the widely-used names for the day of the month. Months arguably don't have widely-used numeric names, although it's pretty reasonably to argue that because numeric month-and-day formatting is so ubiquitous it would have been okay to 1-index the months. It occurs to me that "9/11" is the one date I can think of where the month is commonly verbally referred to by its number.
- samatman 7y agoThat's... a terrible argument. 1970-01-01T00:00:00 is the start of the Unix Epoch, it is definitely not 1970-00-01T00:00:00. This is consistent across all the warty and various ways to represent the Gregorian calendar, the fifth month is always May, no exceptions.
- strbean 7y agoI think parent means that we often say: > I get my check on the first of the month But never really say > I'm going on vacation for the sixth (month) of the year Seems like they are just trying to explain the bad decision, not justify it.
- baddox 7y agoYes, I'm not trying to justify it. And it's not just that we say "the fifth day of May," because it's also true that we can say "the third month." My point is that the fifth day of May is actually named "5" and there's no other name for dates (other than specially=named days, of course).
- paulddraper 7y agoThat consistent with days of the week, which start at 0 on Sunday. The bigger WTF is getYear(), which returns the year minus 1,900.
- pintxo 7y agoWasn't the reason for the 0-indexed month that this would make picking the name of the month from the 0-indexed array of month names easier?
- paulddraper 7y agoIt's bizarre that Java....Java....was able to fix this years before JS even really seriously considered it. I don't know whether JS is fast-evolving or slow-evolving.
- toupeira 7y agoAnd also: > d.getDay() 4 // that's the weekday, use getDate() > d.getYear() 120 // that's the year minus 1900, use getFullYear()
- Aardwolf 7y agoThat's at least as old as the C language, including also years being since 1900: https://en.cppreference.com/w/c/chrono/tm https://en.cppreference.com/w/c/chrono/tm
- DonaldFisk 7y agojava.util.Date copied it from time.h and Javascript copied it from Java.util.Date. ISO 8601 has a sensible date format which is an international standard. Gregorian calendar, YYYY-MM-DD, with MM from 01 to 12, and DD from 01 to 31. Days of the week are from 1 to 7, beginning with Monday. java.util.Date has since been superseded by classes in java.time, which uses ISO 8601.
- alblue 7y agoThis is just one of the many things wrong with the Java Date API: https://stackoverflow.com/a/1969651/130659 https://stackoverflow.com/a/1969651/130659