ES Temporal: 2 Minute Standards
You might have heard that
Temporal has recently reached Stage 3
in ECMA, here's a
#StandardsIn2Min explaination of it...
Date object. It copied
Date from an early edition
of Java and it was intended to be used for programming just about anything
relating to time. While Java itself quickly deprecated and improved their
its own warts and quirks to
Date along the way. As a result,
moment.js became common and essential.
Temporal, now at stage 3 as of this writing, is the result of a
lot of work initiated by maintainers of those projects and shepherded
through the standards process. It introduces lots of rich APIs to the
Temporal object. Large top-level introductions of this sort
(like Temporal, Math and Intl) are exceedingly rare.
Temporal provides a number of objects, all immutable and
serializable, and each with their own methods for reasoning about time in
It contains some fundamental concepts which implement standards for calendar systems and timezones respectively, and set the foundations for how a lot of methods do their work:
Temporal.Instant which is used for dealing with
an instant in time to various degrees of precision.
It also introduces a number of "plain" themed objects geared toward providing APIs for the different ways we think about time not simply in terms of different kinds of precision. For example...
Temporal.PlainTimeis for dealing with wall-clock time that is not associated with a particular date or time zone.
Temporal.PlainMonthDayis for date without a year components, useful for annual events like "The fourth of July" or "Christmas Day".
Temporal.PlainDateTimeis for representing a calendar date and wall-clock time that does not carry time zone information, e.g. December 7th, 1995 at 3:00 PM (in the Gregorian calendar).
Temporal.PlainYearMonthis useful for expressing things like "The October 2020 edition of Vanity Fair".
It also includes...
Temporal.ZonedDateTimeis for reasoning about dates and times in the timezone offsets reckoned by a particular calendar
Temporal.Durationis used for measuring the duration between two temporal objects.
Temporal.nowprovides APIs about current the moment in time.
You can learn a lot more by following through links in the
proposal repo, including helpful
Reference documentation and
cookbook to help you
get started and learn the ins and outs of Temporal which include a (not
production ready) polyfill in every page so that you can open Dev Tools and
explore for yourself.
If you're interested in hearing about the history, development, challenges, inner workings or rationale behind any of this, I recently hosted an edition of our podcast on this topic with guests who worked on the standard.