Why does JavaScript's Temporal API use different types for different time concepts?
Show answer & explanation
Answer: It helps avoid mixing up instants, dates, and durations.
It helps avoid mixing up instants, dates, and durations. ✓ — Temporal provides distinct types for instants, calendar dates, times, durations, and timezone-aware values. This explicit separation helps developers avoid accidentally mixing them, which is a common source of bugs.
It allows timezones to be ignored entirely. — Temporal actually helps handle timezones correctly by providing types that are timezone-aware. It doesn't ignore timezones; it models them explicitly.
It makes the API more complicated than necessary. — The goal is not to add complexity, but to make the meaning of each value clear. The API is designed to be more intuitive once you understand the types.
More Technology questions
- Why can a satellite redness index flag rusting Arctic rivers but still fail to tell which streams are chemically hazardous?
- A service publishes a fresh random number every minute, plus a public log in which each entry carries a fingerprint of the entry before it. What does that chaining add?
- Why can a wall of lava lamps used as a camera feed improve encryption even though the cryptographic software that consumes it is deterministic?
- If an attacker learns a pseudorandom generator's seed and algorithm after watching several outputs, why can the later outputs become reconstructable?
- Why does a physical noise source provide security against an attacker who knows the code, while a phone game shuffle does not?
- At parking-lot speed, why do quiet EVs need alert sounds before tire noise helps?