Fixing JavaScript's Date (2017)
maggiepint.com
maggiepint.com
> 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.Hindsight really is 20/20.
Can you elaborate on this? Was netscape owned/funded by Sun?
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.
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.
> 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.
The bigger WTF is getYear(), which returns the year minus 1,900.
You forgot about east asian languages, which all use numeral months.
https://en.wikipedia.org/wiki/Chinese_calendar#Month
I don't know whether JS is fast-evolving or slow-evolving.
> d.getDay()
4 // that's the weekday, use getDate()
> d.getYear()
120 // that's the year minus 1900, use getFullYear()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.
A good library instants (1582852000000 ms since epoch), durations (5000 ms), periods (2 months), offsets (-0700), timezones (America/Denver), date (4/3/2019), and time (4:45 PM).
Instead I am stuck with good treatment of like two or three of these in any JS library I pick up -- usually instant and duration -- and I have to hammer things to fit.
I've used Joda and java.time a lot, and I have a very high opinion of both.
https://github.com/tc39/proposal-temporal
At a glance, it does follow the same ideas as the great Joda Time library (now a part of the Java standard library), and there's currently a port of this library for JS which is quite nice:
This makes it hard to do "class MyDate extends Date" when targeting ES5 from TS. In fact, if anyone knows an easy solution for that I'd love to hear it.
Thanks for your wonderful feedback though.
What’s this? You’re asking for a solution to “things that don’t work” ️
Hopefully other languages and platforms, including .NET, move to including a sane DateTime library in the standard library too.
Same with Java.
It was still able to introduce a new date API.