Ok, I get that the Date API is problematic, but I wouldn’t expect anything meaningfull from
new Date("not a date").getTime()
anyway. Why would you in the first place?Luckily the new Temporal API is shaping up.
I quite like this one.
Until the new Temporal API comes along, there are some libraries we can use.
- luxon
- dayjs
- or compile chrono (Rust) to WebAssembly
In the process of being replaced.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal
JavaScript has had the
Date
object for handling date and time since its first days. However, theDate
API is based on the poorly designedjava.util.Date
class from Java, which was replaced in the early 2010s; but, because of JavaScript’s goal of backward compatibility,Date
sticks around in the language.Hmm, I can believe that it was based on
java.util.Date
, but I don’t remember that being as unpredictable. I guess, a different API to begin with, would have avoided a lot of problems, though…Damn, I thought you meant JavaScript itself was being replaced.
One can only
undefined