Live data from Hacker News

JavaScript Temporal is coming

developer.mozilla.org

121–130 of 416 posts

Re: JavaScript Temporal is coming

#121

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

It sounds kinda cool and sci-fi-ey, but yeah I have a feeling I'm gonna struggle remembering the name of this new API lol

Re: JavaScript Temporal is coming

#122
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.

Re: JavaScript Temporal is coming

#123
post #58

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 detect the slightest bit of sarcasm but then again it’s hard to read tone in random internet comments.

Re: JavaScript Temporal is coming

#124

From TFA: > 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. 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?…

> Java replaced this implementation in 1997

If that date's correct, they replaced it with another flawed implementation. The 'good' one came much later: https://jcp.org/en/jsr/detail?id=310

> What are the forces at work here?

I feel like I'm always simultaneously engaged in about 5 HN threads at a time, advocating for some combination of immutability, type-safety, and/or no-nulls. It's basically all I do.

By and large, people simply aren't into it. "Because the world is shared and mutable" is a pretty common rebuttal:

4 hours ago: https://news.ycombinator.com/item?id=42876487

2 days ago: https://news.ycombinator.com/item?id=42850569

Re: JavaScript Temporal is coming

#125

Earlier quoted context omitted.

That but also and for me more importantly it does not tell you how to add time - If you add one month of hours to a date in October, it depends on the timezone whether you will end up one hour of local time earlier or not (due to DST), because then +02:00 might be +01:00

While this is true, most often if you want to do "now plus a month" you'll mean "at the same time on the local clock", and disregarding timezone changes, while most often if you want to do "now plus four hours" you'd actually mean four real hours, and you want to calculate in the DST changes to make sure you have four actual hours in your duration

That's how Temporal works:

    >> zdt = Temporal.ZonedDateTime.from("2024-03-09T17:00-05[US/Eastern]")
    >> zdt.add("P1d").toString()
    "2024-03-10T17:00:00-04:00[US/Eastern]"
    >> zdt.add("PT24h").toString()
    "2024-03-10T18:00:00-04:00[US/Eastern]"
If you don't have the time zone and instead just an offset, then Temporal can't do this:

    >> zdt = Temporal.ZonedDateTime.from("2024-03-09T17:00-05[-05]")
    >> zdt.add("P1d").toString()
    "2024-03-10T17:00:00-05:00[-05:00]"
    >> zdt.add("PT24h").toString()
    "2024-03-10T17:00:00-05:00[-05:00]"
Adding 1 day still works the same with respect to civil time but the offset is wrong since it doesn't account for the DST change. And adding 24 hours leads to a different result as well. This is one of the reasons why RFC 9557 is so important for serializing zoned datetimes when you want your arithmetic to be DST safe. Previously, to get this right, you had to include a time zone out of band somehow along with your RFC 3339 timestamp.

Re: JavaScript Temporal is coming

#126
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).

With that out of the way, very excited for Temporal and am very thankful to the people doing this hard work!

Re: JavaScript Temporal is coming

#127
post #37

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…

It's not just the major browser makers. I was working on a JavaScript inference engine around when ES6 started to roll out, I had decent ES5 support but when all the syntatic updates came I had to give up. They basically killed the JavaScript ecosystem with all the updates. We only have complile to JS languages now. Those that still writes in vanilla JS are like those who still build apps in assembly langauge.

> We only have complile to JS languages now. Those that still writes in vanilla JS are like those who still build apps in assembly langauge.

I strongly disagree, it's never been easier and more pleasant to write modern JS without transpilers. I've only rarely had to reach for a framework or transpiler in the last few years.

Re: JavaScript Temporal is coming

#128

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.

I spent a day fighting with date-fns trying to get some date calculations working and was to the point I was questioning if my entire approach was flawed because there was no reason I should be spending that much time figuring our some simple date calculations. Eventually I decided to try swapping to Luxon. 30 minutes later and it was all working.

I'm still guessing I misunderstood something fundamental about date-fns, but for now I'm advocating for Luxon.

Re: JavaScript Temporal is coming

#129

Earlier quoted context omitted.

I get that it’s more correct, but it assumes that Europe/Paris is a constant representation of how to apply the timezone-specific stuff but that’s incorrect. For example, ‘2025-06-20T17:00:00+02[Europe/Dublin]’ is a very different time if it’s created today vs if it were created in 1760 [1]. That’s a very extreme example, but timezone rules change and dates created from before the change was announced would be interp…

Can you provide a concrete example? Ideally using Temporal to show where it's going wrong. Like, if you created `2025-06-20T17:00:00+02[Europe/Dublin]` (the instant) in 1760, then its civil representation would be different, to account for the rules in place at the time. And then if you went to deserialize it today, Temporal would reject it. You'd get an error, because the rules in place when the string was serialize…

I must be misunderstanding what you’re saying. How does Temporal know to reject something serialized from before a rule was changed when the creation time of the serialized representation isn’t encoded? You’re saying in 1760 [Europe/Dublin] would be a different string vs today? A more concrete example is normal time-zone rule changes - `2025-06-20T17:00:00+02[Europe/Dublin]` would represent different instants if Dubling passed a new DST rule adjusting the clock back by 15 minutes at 2025-06-20T16:50:00+02[Europe/Dublin] - then the meaning of the instant is different because now there’s 2 different `2025-06-20T17:00:00+02[Europe/Dublin]` and which one you get will depend on when you deserialize.

Re: JavaScript Temporal is coming

#130

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

temporal

> 1. of or relating to time as opposed to eternity

> 2. of or relating to grammatical tense or a distinction of time

> 3. of or relating to time as distinguished from space

https://www.merriam-webster.com/dictionary/temporal

Sounds like a good name to me.

Post reply on HN