Temporal: The 9-year journey to fix time in JavaScript

bloomberg.github.io

784 points by robpalmer 5 days ago


wesselbindt - 4 days ago

I'm very happy about this. The fact that Temporal forces you to actually deal with the inherent complexities of time management (primarily the distinction between an instant and a calendar datetime) makes it incredibly difficult to make the mistakes that Date almost seems designed to cause. It's a bit more verbose, but I'll take writing a handful of extra characters over being called at 3AM to fix a DST related bug any day of the week.

Vinnl - 4 days ago

> Whilst Firefox was able to implement Temporal as it was being specced - thanks to the great work of André Bargull (known online as Anba)

It's worth highlighting that André is actually a volunteer contributor who managed to implement the whole thing by themselves.

Animats - 4 days ago

I went through a similar decade-long fire drill around ISO8601 date parsing in Python.[1] Issue started in 2012, and after about a decade a solution was in the standard library.

[1] https://groups.google.com/g/comp.lang.python/c/Q2w4R89Nq1w

VanCoding - 5 days ago

A big step in the right direction, but I still don't like the API, here's why: Especially in JavaScript where I often share a lot of code between the client and the server and therefore also transfer data between them, I like to strictly separate data from logic. What i mean by this is that all my data is plain JSON and no class instances or objects that have function properties, so that I can serialize/deserialize it easily.

This is not the case for Temporal objects. Also, the temporal objects have functions on them, which, granted, makes it convenient to use, but a pain to pass it over the wire.

I'd clearly prefer a set of pure functions, into which I can pass data-only temporal objects, quite a bit like date-fns did it.

plucas - 5 days ago

Would have been interesting to connect back to Java's own journey to improve its time APIs, with Joda-Time leading into JSR 310, released with Java 8 in 2014. Immutable representations, instants, proper timezone support etc.

Given that the article refers to the "radical proposal" to bring these features to JavaScript came in 2018, surely Java's own solutions had some influence?

nekevss - 5 days ago

Super happy to see Temporal accepted!

Congrats to all the champions who worked super hard on this for so long! It's been fun working on temporal_rs for the last couple years :)

zvqcMMV6Zcr - 5 days ago

> Safari (Partial Support in Technology Preview)

Safari confirmed as IE Spiritual successor in 2020+.

wpollock - 5 days ago

> "It was a straight port by Ken Smith (the only code in "Mocha" I didn't write) of Java's Date code from Java to C."

This is funny to me; Java's util.Date was almost certainly a port of C's time.h API!

QGQBGdeZREunxLe - 4 days ago

Noticed that converting between certain calendars is not supported. Was that choice intentional?

    const today = Temporal.PlainDate.from("2569-03-11[u-ca=buddhist]"); 
    today.toLocaleString("en", { calendar: "hebrew" });
    > Uncaught RangeError: calendars "buddhist" and "hebrew" aren't compatible
bnb - 5 days ago

Can't wait for it to land in the server-side runtimes, really the last thing preventing me from adopting it wholesale.

xp84 - 4 days ago

They travelled through time (forward, at 1X) by nine years to do this for us. I appreciate it.

avandecreme - 4 days ago

I didn't know about https://docs.rs/temporal_rs/latest/temporal_rs/

I wonder if it has a chance to replace chrono and jiff in the rust ecosystem.

alanning - 4 days ago

The Temporal Cookbook on TC39's site provides examples of how using the new API looks/feels:

https://tc39.es/proposal-temporal/docs/cookbook.html

For example, calc days until a future date: https://tc39.es/proposal-temporal/docs/cookbook.html#how-man...

...or, compare meeting times across timezones: https://tc39.es/proposal-temporal/docs/cookbook.html#book-a-...

the__alchemist - 4 days ago

Maybe I will be able to move away from my custom/minimal DT lib, and ISO-8601 timestamp strings in UTC. JS datetime handling in both Date and Moment are disasters. Rust's Chrono is great. Python's builtin has things I don't like, but is useable. Date and Moment are traps. One of their biggest mistakes is not having dedicated Date and Time types; the accepted reason is "Dates and times don't exist on their own", which is bizarre. So, it's canon to use a datetime (e.g. JS "Date") with 00:00 time, which leads to subtle errors.

From the link, we can see Temporal does have separate Date/Time/Datetime types. ("PlainDate" etc)

FireBeyond - 4 days ago

> Higher-precision timestamps (nanoseconds, at a minimum)

I get HFT, but I have a hard time comprehending a need for a Bloomberg Terminal to be talking in picoseconds, as in fractions of a billionth of a second.

tmpfile - 4 days ago

I’d like to have interval types for example

   const D = new Temporal()
   const t = new Interval({minutes:5})
   const v = D.add(t)
matheus-rr - 4 days ago

The Java parallel is apt. Joda-Time dominated the ecosystem for about 8 years before JSR 310 landed in Java 8 (2014). One thing that helped there was a clear, single release target.

What I keep thinking about with Temporal is the adoption timeline question isn't really 'is it specced?' anymore, it's 'what minimum runtime version do I need?' Node.js, Deno, Bun all need to ship it stably, and then the practical floor for usage is wherever most prod environments are. The polyfill situation (@js-temporal/polyfill and others) doesn't really collapse until that happens.

So the speccing is done but I think we're still a couple of LTS cycles away from it being genuinely boring to reach for Temporal.

kemayo - 5 days ago

> Developers would often write helper functions that accidently mutated the original Date object in place when they intended to return a new one

It's weird that they picked example code that is extremely non-accidentally doing this.

corentin88 - 4 days ago

Temporal is a good idea, but the API is too complicated for broad adoption:

- new Date() equivalent in Temporal is `const now = Temporal.Now.zonedDateTimeISO();`.

- Date.now() equivalent is `Temporal.Now.instant().epochMilliseconds`

- It’s PascalCase, where JS is mostly snakeCase.

- nanoseconds per default. who needs that except Bloomberg? It should have been an option

It’s definitely great all the efforts put in place, but it’s not going to be a replacement to Date which such a complicated design.

redbell - 5 days ago

Oh, for a second, TeMPOraL (https://news.ycombinator.com/user?id=TeMPOraL) came to my mind!

SoftTalker - 5 days ago

It's been a while since I worked in JS but dealing with dates/times, and the lack of real integer types were always two things that frustrated me.

pbowyer - 4 days ago

If you were creating a new programming language in 2026, which DateTime/Temporal library would you copy and why?

johncomposed - 4 days ago

As a side note, huge fan of Promise.allSettled. When that dropped it cleaned up so much of the code I was writing at the time.

virgil_disgr4ce - 5 days ago

Pretty big fan of Temporal. Been using the polyfill for a while. Very nice to use a modern, extremely well thought-through API!

KolmogorovComp - 4 days ago

Doesn't the implementation being in rust for many browser (`temporal_rs`) make it possibly slower than it could be in pure JS? Calendar is not very intensive process, so I would not be surprised if the slowness of boundary passing make it slower.

klysm - 4 days ago

Bravo to the designers of this library. It’s well implemented and I’ve been using the poly fill for years now

parampathonmon2 - 4 days ago

Nice to see Temporal finally landing after such a long standardization process. The duration and timezone handling should simplify a lot of date math that libraries like moment and date-fns have been covering.

philipallstar - 5 days ago

> have to agree on what "now" means, even when governments change DST rules with very little notice.

I didn't spot how Temporal fixes this. What happens when "now" changes? Does the library get updated and pushed out rapidly via browsers?

gangnamdotori - 4 days ago

Temporal API is fascinating. Time handling has always been painful in programming languages. Curious how widely this will get adopted in production systems.

ramon156 - 4 days ago

TIL temporal_rs was a thing. Not to be biased, but I think it's awesome how much Rust is used in the JS ecosystem. I saw Vite using oxc in some parts. Love it!

ChrisArchitect - 5 days ago

A good article and discussion from January:

Date is out, Temporal is in

https://news.ycombinator.com/item?id=46589658

tracker1 - 4 days ago

Looking at the caniuse results... f*king Safari (and Opera)...

https://caniuse.com/temporal

normie3000 - 5 days ago

No mention of JodaTime?

samwho - 5 days ago

Thanks for linking to my silly little quiz in the article! :)

thinkindie - 4 days ago

coming from PHP, it's incredible how many times I've been bitten by glitches with managing time with JS clientside.

Banou - 4 days ago

Temporal is nice but I've tried using it and had terrible performances. Hope the implementations get better in the future.

kemitchell - 4 days ago

> The first proposal I worked on was Promise.allSettled, which was fulfilling.

Har har.

sharktheone - 5 days ago

Very happy for it finally being there!

stevefan1999 - 4 days ago

I thought this Temporal is about the durable execution Temporal, well it is about time...

darepublic - 5 days ago

My playbook for JavaScript dates is.. store in UTC.. exchange only in UTC.. convert to locale date time only in the presentation logic. This has worked well for me enough that Im skeptical of needing anything else

ChrisArchitect - 5 days ago

Aside: Bloomberg JS blog? ok.

bpiroman - 4 days ago

I wish JavaScript held onto the name Mocha :)

jon_kuperman - 5 days ago

What a journey!

hungryhobbit - 5 days ago

From the article:

    const now = new Date();
The Temporal equivalent is:

    const now = Temporal.Now.zonedDateTimeISO();
Dear god, that's so much uglier!

I mean, I guess it's two steps forward and one step back ... but couldn't they have come up with something that was just two steps forward, and none back ... instead of making us write this nightmare all over the place?

Why not?

    const now = DateTime();
NooneAtAll3 - 5 days ago

so Temporal is copying cpp's std::chrono?

ventuss_ovo - 4 days ago

interesting point about immutability

nehalem - 4 days ago

And yet another modernisation of the web platform sabotaged by Apple and their misguided (malicious?) refusal to update their devices continually.

https://caniuse.com/temporal

It will take years until this can be widely used as intended.

patchnull - 5 days ago

[flagged]

shevy-java - 4 days ago

Good. Now someone has to fix JavaScript.

patchnull - 4 days ago

[flagged]

sriramgonella - 4 days ago

[flagged]

newzino - 5 days ago

[flagged]

patchnull - 4 days ago

[dead]

aplomb1026 - 5 days ago

[flagged]

eggsandbeer - 4 days ago

[dead]

ilovesamaltman - 4 days ago

[flagged]

julius_eth_dev - 4 days ago

[flagged]

patchnull - 4 days ago

[flagged]