news.volyx.in

Date is out, Temporal is in (piccalil.li)

464 points by coinfused · 282 days ago · 204 comments on HN

Article summary

The article discusses the limitations and quirks of JavaScript's Date object, which can lead to inconsistencies and errors when working with dates and times. The author argues that the Date object is mutable, which can cause unintended changes to date values. A new API, Temporal, is introduced as a replacement for Date, offering a more sensible and explicit way of working with dates and times. Temporal provides a namespace object with static properties and methods for calculating durations, representing points in time, and accessing the current moment.

Main themes

  • JavaScript Date object limitations
  • Temporal API introduction
  • Date and time handling
  • Mutability and immutability
  • Time zone support

What commenters say

  • The Date API is problematic due to its quirks and lack of support for time zones, making it difficult to work with dates and times across different regions.
  • Temporal is a significant improvement over the Date API, offering a more explicit and sensible way of working with dates and times, but its adoption is currently limited due to poor native support.
  • The use of mutable objects to represent dates can lead to unintended changes and errors, and Temporal's approach to creating new objects instead of modifying existing ones is a better design choice.
  • The Temporal API is not yet widely supported, and its polyfill is relatively large, which may hinder its adoption in production environments.
  • Some developers find the Date API to be sufficient and easy to work with once its quirks are understood, while others appreciate the more explicit and robust nature of the Temporal API.
  • The Temporal API's design choices, such as not allowing the creation of an Instant from a year, month, and day, are intentional and aimed at avoiding confusion between local and UTC values.