Temporal is great. I've been using it for a while in production using a polyfill [1], and it solves all issues I've encountered with the old Date() API (which is a lot).<p>It clearly takes inspiration from other high-quality time libraries such as chrono in Rust and Joda Time in Java and combines them into a nice API that's pretty comfortable to use.<p>Yes, it is a bit more complex to handle since it separates time into naive time, instant and zoned time. But by experience, developers only confront complexity when they are forced to, and time _is_ complex.<p>If you want to do the operation "add one day to this timestamp", you _must_ decide whether that timestamp is local to a specific timezone and which one. Otherwise you'll get a bug twice per year due to DST, or when the user switches time zones, or when you deploy on a server with a different timezone.<p>It even solves the serialization issue of the difference between a "fixed-offset" timestamp (e.g. 2025-01-01T00:00+02:00) and one in a specific timezone (e.g. Europe/Paris).<p>[1]: <a href="https://www.npmjs.com/package/temporal-polyfill" rel="nofollow">https://www.npmjs.com/package/temporal-polyfill</a>
Man, that took some time to find in the docs:<p><i>Temporal.ZonedDateTime.prototype.withTimeZone()</i> [0], which allows to convert from one timezone to another<p><pre><code> const meetingTime = Temporal.ZonedDateTime.from(
"2021-08-01T12:00[America/New_York]",
);
const meetingTimeInParis = meetingTime.withTimeZone("Europe/Paris");
console.log(meetingTimeInParis.toString()); // 2021-08-01T18:00:00+02:00[Europe/Paris]
</code></pre>
To me, timezone translations as well as durations are such an essential thing which libraries must handle, and it's nice to see that Temporal handles both. But it looks like Temporal.Duration doesn't offer a custom `format` function, for example `duration.format('H\hmm\m')` or something like that to format a duration into 1h03m.<p>[0] <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/ZonedDateTime/withTimeZone" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...</a>
There are quite a few things marinating in the TC39 pot right now. This is one that I wish would ship sooner, rather than later. I do recognize that it takes dev effort (on the part of v8, JSC, and SpiderMonkey engineers) to get the major browsers to support any of these new features. So I truly appreciate all that folks are doing to move the ball forward. The impatient person in me is cheering, "now get Records and Tuples going too! You can skip that silly Pipe-syntax war if you want!"
Anyone knows how the data about each timezone stays updated within Temporal? Does the TC39 update the data somewhere, then each browser copies that data internally and releases a new version of the browser? If a user visits my website and this user has not updated their browser with the new data, will they see incorrect hours?<p>For example Mexico removed DST in 2022 [1]. When using third party libraries like pytz or moment-timezone, you just update the library on your side with the updated data for Mexico. Or bump the language if it's handled in the standard library. What about Temporal and my visitors' browser?<p>[1] <a href="https://en.wikipedia.org/wiki/Time_in_Mexico" rel="nofollow">https://en.wikipedia.org/wiki/Time_in_Mexico</a>
They should add an event to detect when someone changes timezones. That could be another entry in the "falsehoods that programmers believe about time": programmers believe that your timezone is fixed during usage. But in reality there are millions of people moving between timezones every day.
Very sad that .Now is not a function call. It shouldn't be a property.<p>Evaluating .Now multiple times in a loop will yield different values, which is unexpected.<p>C# did the same and it shouldn't have been:<p><a href="https://ericlippert.com/2014/05/19/when-should-i-write-a-property/" rel="nofollow">https://ericlippert.com/2014/05/19/when-should-i-write-a-pro...</a>
I really like the temporal proposal, except for one thing: they rely on reference equality in comparisons. On other words:<p><pre><code> Temporal.Instant.from('2020-01-01') != Temporal.Instant.from('2020-01-01')
</code></pre>
This isnt inherently bad, but it effectively removes the ability to use these objects as Map keys or collecting them in a Set. I know why that decision was made, I'm just sad that this wont be possible. Maybe there will be some version that relies on records and tuples, if these ever make it.
I get that the naming Temporal is used for avoiding conflicts with typical time objects like Moment, Datetime, etc. But isn't it a terrible name? At first glance I thought it was some kind of garbage collection control
Related. Others?<p><i>JavaScript Temporal Is Coming</i> - <a href="https://news.ycombinator.com/item?id=42809834">https://news.ycombinator.com/item?id=42809834</a> - Jan 2025 (18 comments)<p><i>Mozilla: Temporal (Limited Availability)</i> - <a href="https://news.ycombinator.com/item?id=42776548">https://news.ycombinator.com/item?id=42776548</a> - Jan 2025 (1 comment)<p><i>Is It Time for the JavaScript Temporal API?</i> - <a href="https://news.ycombinator.com/item?id=29712118">https://news.ycombinator.com/item?id=29712118</a> - Dec 2021 (100 comments)<p><i>Temporal: Getting started with JavaScript's new date time API</i> - <a href="https://news.ycombinator.com/item?id=27661667">https://news.ycombinator.com/item?id=27661667</a> - June 2021 (194 comments)<p><i>JavaScript Temporal</i> - <a href="https://news.ycombinator.com/item?id=27395236">https://news.ycombinator.com/item?id=27395236</a> - June 2021 (1 comment)<p><i>JavaScript Proposal Temporal for Dates is now stage 3</i> - <a href="https://news.ycombinator.com/item?id=26432346">https://news.ycombinator.com/item?id=26432346</a> - March 2021 (1 comment)
From TFA:<p>> When JavaScript was created in 1995, the Date object was copied from Java's early, flawed java.util.Date implementation. Java replaced this implementation in 1997, but JavaScript is stuck with the same API for almost 30 years, despite known problems.<p>I'm not a JavaScript or web developer, and I was surprised by the above. Can anyone comment on why the language was stuck with an inadequate api for so long? What are the forces at work here?
My work does a lot of stuff with time and scheduling, and let me tell you having timezone-unaware date/time objects distinct from specific points in time will be so damn useful. The old Date class made it really easy to accidentally screw that up. Third party libraries help, but something as important and fundamental as time really should have a good built-in implementation.
Does this mean we can finally stop downloading and running a third of a MB of js on every website? moment.js, luxon, date-fns, are all obsolete? <a href="https://bundlephobia.com/package/moment@2.30.1" rel="nofollow">https://bundlephobia.com/package/moment@2.30.1</a>
2024: Nested CSS
2025: Temporal<p>Once we can style <option>'s HTML/CSS/ECMA will be complete. Thank you for everyone's hard work. Let's focus on interop and PWA apis!
This is the most extraordinary thing that I have personally seen in my career as a software developer, and I have worked in many different fields and different languages and on different platforms, but this is by a very wide margin the most exciting.
I used this (via polyfill) for my Typescript implementation of the calendar of the church, and it was fabulous. Using the old Javascript dates I felt like I was always tripping over something... this was actually nicer than Python's (already quite good) datetime support.<p><a href="https://github.com/grahame/church-calendar">https://github.com/grahame/church-calendar</a>
Carbon is a similar class in the PHP world that's inherited from DateTime. This gives a good description of how working with mutable timestamps can cause problems, because methods like $newInstance = $instance->addDay() modify the original instance and return it, rather than returning a copy that's a day later:<p><a href="https://carbon.nesbot.com/docs/" rel="nofollow">https://carbon.nesbot.com/docs/</a><p>So it's best to mostly use CarbonImmutable so that a new instance is always returned, which works better for higher-order programming style that's closer to pure functional programming. I do wish that Carbon was immutable by default, with CarbonMutable as a fallback when necessary, but it's too late for them to change it now.<p>I could see a project using use..as statements and/or aliases in config/app.php (edit: in Laravel) to import CarbonImmutable and Carbon as aliases like CRBN and CRBNMUT respectively, so that code works as intended without monkey patching or otherwise swapping the classnames and losing code portability.
At first glance, this seems to be in the JodaTime/NodaTime/Js-Joda tradition of representing different "granularities" of date and time information with distinct types, e.g. with and without timezone information. I'm not sure if there's a formal relationship, since this seems to use different names.<p>I personally like that approach, but I'm not sure how much sense that makes without static typing. (Maybe TypeScript is established enough that JavaScript APIs are now designed with TypeScript in mind?)<p>From experience with js-joda, there's a definitely learning curve compared to moment's "one size fits all" type for all things date related. But I found that a lot of stupid mistakes of the kind "a person's age is wrong for an hour after midnight during daylight savings time" are prevented by default.
I've used Temporal a bit with a polyfill. It's a huge improvement.<p>There's no "it's coming" really. With build processes and polyfills there's no reason to to use it already.
> Java replaced this implementation in 1997<p>I don't think it's safe to say, more direct comparison of JS's Temporal would be java.time[1], which was introduced in Java 1.8 in 2014.<p>[1]: <a href="https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html" rel="nofollow">https://docs.oracle.com/javase/8/docs/api/java/time/package-...</a>
This is great. You need to write so much code to do conversion between arbitrary timezones reliably now. And even if you don't mind including yet another (large) dependency instead, even those almost all have problems around DST boundaries/ambiguous dates as you simply don't have access to the timezone rules in the browser right now.
With any new DateTime object in any language I usually look at its persistent fields to judge what the memory and access characteristics are.<p>In case of Temporal it looks like that Chrome goes the JavaScript Date way as it only holds the timestamp:<p>extern class JSTemporalInstant extends JSObject {
nanoseconds: BigInt;
}<p>And then calendrical fields are computed on the fly. Is this correct?
Long-needed, though I think it'll take the ecosystem quite a while to catch up and standardize around it<p>For one: a couple years ago my company migrated from moment to dayjs, which was a huge improvement and carried most of the benefits of Temporal. So even if it were available tomorrow, migration wouldn't be a super high priority for us<p>Still a great thing!
Wow, this is great! We were using the proposal library at my job when I first joined, but switched to moment since Temporal seemed frozen. For what it's worth, moment is excellent too, but having good datetime support in the standard library is going to be fantastic.
The ECMAScript official docs.<p><a href="https://tc39.es/proposal-temporal/docs/" rel="nofollow">https://tc39.es/proposal-temporal/docs/</a><p>Not the most intuitive name though.
Each time I see a programming language upgrade its base library to improve date/time handling, they all look eerily similar to the Java open source library JodaTime, which eventually became JSR-310 (essentially the "2.0" version of JodaTime in the Java base library). Does anyone else notice this? Except for leap seconds, I have never seen a real world business problem that I cannot solve with the current Java date/time APIs.
Cannot wait. That said, somehow I don't think it will help us with a UK-based API provider we work with that provide us with ISO-encoded UTC time strings that are actually BST during northern hemisphere summer (or localised strings, e.g. +6 where the datetime component is actually UTC).
I look forward to the day it's widely available.<p>But red across the board at <a href="https://caniuse.com/temporal" rel="nofollow">https://caniuse.com/temporal</a> looks like it's still far away, and a 20Kb polyfill seems heavy compared to the 2Kb size of Day.js
> Implementations of the new JavaScript Temporal object are starting to be shipped in experimental releases of browsers.<p>I can't get it working with Firefox developer edition or firefox nightly on Fedora Linux. What am I missing here? Can someone please guide me?
Great video covering the API: <a href="https://youtu.be/oOK3UzLJ_Cs?si=1MJYtFBmcyJs4tLj" rel="nofollow">https://youtu.be/oOK3UzLJ_Cs?si=1MJYtFBmcyJs4tLj</a>
I'm honestly really excited for this to be more widely adopted to the point it can be used without polyfills. While the API is a little verbose for my liking, it's extremely capable.<p>Being able to replace all the various date and time libraries with something browser-native is a massive win for bundle sizes, as even the most lightweight ones are going to start creeping up there once you're dealing with localisation on top of it.
It’s almost a shame, considering all the effort that went into Moment and Luxon, which will largely be superseded. Luxon especially is a joy to work with.
Curious to see how Temporal works with JS on the client side!<p>It’s an awesome tool for durable execution, I’ve been using it in my OSS projects, and it has been instrumental in building a leading Reverse ETL platform powered by Temporal.<p><a href="https://github.com/Multiwoven/multiwoven">https://github.com/Multiwoven/multiwoven</a>
I’ve used date libraries from several languages and they’re all pretty awkward, but Ruby seems to have a very elegant solution thanks to the fact that primitives are also objects, so for example you can write things like 1.minute.ago or 1.day.from.now, which really helps in quick code comprehension.
I was really confused for a minute, I thought this was referring to the Uber spinoff durable execution framework <a href="https://temporal.io/" rel="nofollow">https://temporal.io/</a>
Umm..I am not sure how the Islamic/Hijri calendar gonna work. Tomorrow is the first Shabaan in Pakistan but it is still 30th Rajab in Saudia. How will JS figure this difference out?
> working with dates and times in JavaScript will be hugely simplified<p>> To help you get up to speed, there are over 270 pages of Temporal docs on MDN<p>Not that I'm complaining about extensive documentation, but seeing these two lines juxtaposed doesn't inspire much confidence.
Can someone who's been following this explain why they're designing a new API instead of merging one of the successful open source APIs into the standard?
The vast majority of websites should be calculating dates in a server and merely presenting them to clients.<p>I have wondered why there isn’t a span style element which takes a UTC timestamp and presents it to the user in their preferred time zone. I even wonder if it could be done in private way so that JS cannot even access the value (made more difficult by layout and size).<p>Similarly a form element for date times could simply return the UTC from the local choice.<p>I am just wondering out loud and not an expert.
Just want to chime in as someone who from time-to-time (heh) has to deal with datetime-related things and say, I hope for nuclear annihilation upon all clocks and other miscellaneous time-telling instruments, and most of all to whomever it is the world over that decides that, no, we're special and don't need to follow any kind of logic for our timezones (looking at you, China but also basically everyone else in the world).<p>With that out of the way, very excited for Temporal and am very thankful to the people doing this hard work!
Future generations will no doubt remember this announcement as a revolutionary leap into a brighter future. But I'm sure I'll still be using Moment.js ten years from now the way I'm still using JQuery 3.x now.<p>Javascript is all we have for front end web apps now, impoverished as it is as a language. But excuse me if I don't get excited every time a proposal is rolled out to bring it close to the 21st century.