Hello folks, I think it was time for this update.
I mean, you could work with Date
, but it sucks. A lot.
- Time zone handling was limited and inconsistent
- Parsing behavior was unreliable across browsers
- Mutability. Methods like
setDate()
orsetMonth()
modified the original object - Months were zero-based (0 for January), resulting in off-by-one errors
- No support for durations or date arithmetic
- Formatting and localization were inconsistent across browsers
- Calendar systems were not supported… and so on and so forth
Want smart web dev tips like this delivered straight to your inbox?
JavaScript, CSS, performance, best practices, and tools like Temporal that actually make your life easier.
→ Follow 300+ webdevs and join the newsletter
Introducing the New Temporal API
Temporal is a new API introduced in ECMAScript 2022 designed to replace the broken Date
— completely.
In comparsion to the Date
it is not a Constructor. Temporal is a namespace, like Intl
, which means, you cannot use it with the new
operator or call it as a function as well.
This provides you with:
- Immutable data structures
- Precise time zone and calendar control
- Consistent parsing and formatting
- An API design based on value objects
It doesn’t mutate. It doesn’t guess. It doesn’t surprise you.
Temporal has a complicated but extremely powerful API. It provides over 200 methods across multiple classes, so it can seem very complex.
But I am here to break down what you really need.
Top comments (5)
man, about time they fixed that date mess - working with time zones always wrecked my head. you ever feel like some old stuff just never really goes away unless someone gets stubborn and redoes it right?
Yeah, feels like it's the nature of JavaScript ;-)
Nice post!
Thank you!
Is it supported by retail versions of any browser or backend runtime yet?