I’d like to have interval types for example const D = new Temporal() const t = new Interval({minutes:5}) const v = D.add(t)
It is called Duration.
Temporal: The 9-year journey to fix time in JavaScript
201–210 of 284 posts
Re: Temporal: The 9-year journey to fix time in JavaScript
#202Maybe 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…
Re: Temporal: The 9-year journey to fix time in JavaScript
#203Earlier quoted context omitted.
This was an intentional design decision. We wanted to make sure all the temporal types could be serialize/deserializable, but as you mentioned, you couldn't implicitly go back to the object you started with as JSON.parse doesn't support that. Instead the onus is on the developer to re-create the correct object they need on the other side. I don't believe this is problematic because if you know you're sending a Date,…
So it's intentional to make people pass down raw strings versus making the communication safe(er) by default?
If you really want that, it's not very hard to design a pair of functions `mySerialize()`, `myDeserialize()` that's a thin wrapper over `JSON.parse`.
Re: Temporal: The 9-year journey to fix time in JavaScript
#204Looking at the caniuse results... f*king Safari (and Opera)... https://caniuse.com/temporal
And I have to support safari while dealing with all the problems that are mentioned in this article. Maybe there is a polyfill.
Re: Temporal: The 9-year journey to fix time in JavaScript
#205I'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 a…
npmjs.com/package/temporal-fun
Re: Temporal: The 9-year journey to fix time in JavaScript
#206Looking at the caniuse results... f*king Safari (and Opera)... https://caniuse.com/temporal
Re: Temporal: The 9-year journey to fix time in JavaScript
#207Looking at the caniuse results... f*king Safari (and Opera)... https://caniuse.com/temporal
perhaps don't be hard on them, Chrome released this to stable 2 months ago.
Re: Temporal: The 9-year journey to fix time in JavaScript
#208Earlier quoted context omitted.
You would need to use the `reviver` parameter of `JSON.parse()` to revive your date strings to Temporal objects. As others have said, it's a simple `Temporal.from()` https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Having to provide a complete schema of your json everywhere your json gets parsed negates the advantages of json.
Re: Temporal: The 9-year journey to fix time in JavaScript
#209Re: Temporal: The 9-year journey to fix time in JavaScript
#210I'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 a…
Technically, you're not likely to to have to fix a DST bug at 3AM any day but Sunday.
Some countries start on a Friday or Saturday and until 2022 Iran could start any day of the week although never at 3AM.