Temporal: A 9-year journey to fix time in JavaScript
5 hours ago
- #JavaScript
- #Temporal
- #DateTime
- Temporal is a new JavaScript API for handling dates and times, designed to replace the problematic Date object.
- The Date object in JavaScript was originally ported from Java in 1995, leading to issues like mutability, inconsistent month arithmetic, and ambiguous parsing.
- Temporal provides immutable, timezone-aware, and calendar-aware datetime types, addressing the shortcomings of Date.
- The proposal for Temporal started in 2017 and reached Stage 4 in 2024, making it part of the ECMAScript specification (ES2026).
- Temporal includes types like ZonedDateTime, Instant, PlainDate, and Duration, offering precise and flexible datetime handling.
- The implementation of Temporal involved collaboration across companies like Bloomberg, Microsoft, Google, and Igalia, and was supported by the temporal_rs library.
- Temporal is already supported in major browsers like Firefox, Chrome, and Edge, as well as in TypeScript and Node.js.
- Future work includes integrating Temporal with web APIs like date pickers and DOMHighResTimeStamp.
- Temporal represents a significant improvement in JavaScript's datetime handling, solving long-standing issues through community collaboration.