Dates and Times in JavaScript
JavaScript
Date
is broken in ways that cannot be fixed without breaking the web. As the story goes, it was included in the original 10-day JavaScript engine hack and based on java.util.Date, which itself was deprecated in 1997 due to being a terrible API and replaced with a better one. The result has been for all of JavaScript’s history, the built-inDate
has remained very hard to work with directly.Starting a few years ago, a proposal has been developing, to add a new globally available object to JavaScript,
Temporal
. Temporal is a robust and modern API for working with dates, times, and timestamps, and also makes it easy to do things that were hard or impossible withDate
, like converting dates between time zones, adding and subtracting while accounting for daylight saving time, working with date-only or time-only data, and even handling dates in non-Gregorian calendars. Although Temporal has “just works” defaults, it also provides fine-grained opt-in control of overflows, interpreting ambiguous times, and other corner cases. For more on the history of the proposal, and why it’s not possible to fixDate
itself, read Maggie Pint’s two-part blog post “Fixing JavaScript Date”.
[…]
https://blogs.igalia.com/compilers/2020/06/23/dates-and-times-in-javascript/