3

I try to use Temporal in Chrome, but it fails:

Temporal.DateTime.from("2019-11-26T14:58:54.147Z")

Uncaught ReferenceError: Temporal is not defined at :1:1

Version: Chromium 78.0.3904.108

How to use Temporal in Chrome?

BTW. Above question is solved, but ...

But I want more. I don't want to parse strings and convert them to an object over and over again. I want to parse a JSON string and get nice high level DateTime objects immediately.

Source: https://github.com/guettli/lets-fix-json/blob/master/README.md#add-datetime

Justin Grant
  • 44,807
  • 15
  • 124
  • 208
guettli
  • 25,042
  • 81
  • 346
  • 663

2 Answers2

6

When the question was asked, Temporal was a Stage 2 proposal, so it wasn't surprising if Chrome's V8 didn't have it at that time. (It certainly wouldn't be unflagged.)

Typically JavaScript engines don't implement proposals until Stage 3 (that's part of what Stage 3 is for — more about the stages here). Usually they're behind a flag initially, the eventually unflagged once they've been sufficiently field-tested, but Temporal is a special case; from the explainer linked above (their emphasis):

NOTE: Although this proposal's API is not expected to change, implementers of this proposal MUST NOT ship unflagged Temporal implementations until IETF standardizes timezone/calendar string serialization formats. See #1450 for updates.

V8 support for temporal is underway as of June 2022; here's the tracking issue for it.

In the meantime, the proposal links to polyfills you can use here.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
2

As of today, Temporal is a Stage 3 propsal.

It is currently not implemented in any browser. The process of implementation is ongoing, at least in Chrome.

There is a polyfill available for experimental usage. It follows closely the existing Temporal spec.