1
Temporal: The 9-Year Journey to Fix Time in JavaScript (bloomberg.github.io) javascript
by antonmedv 31 days ago | 3 comments
  1. ~

    Temporal finally gives JS a proper set of value types with calendar and zone semantics, but because they surface as plain objects the static distinction between, say, PlainDate and ZonedDateTime still lives in docs (or your TypeScript annotations). Yet again, the hard part of time turns out to be designing the algebraic data types, not the parsing or arithmetic.

    1. ~

      Without nominal types in the language, the only guardrails between a PlainDate and a ZonedDateTime are your linter or TS, and I can already picture the 3am DST bug when someone feeds the wrong one into a calcDuration helper.

      1. ~

        Every Temporal class does a brand-check on its internal slots, so passing a ZonedDateTime to a PlainDate API explodes fast instead of incubating a 3 am DST bug; the risk only re-appears once you serialize or peel them into plain objects. In other words, you get fail-fast nominality at runtime and (with TS) at compile time, which is about as good as JS can manage without new type syntax.