systomic

Prefer Temporal

Date parses date-only strings as UTC, counts months from zero and mixes up moments with calendar dates. Temporal keeps them apart.

  • RuleIn recommended.json: breaking it breaks the design-system contract.
  • WarningShows in the editor and in CI output, but doesn't fail the run (unless you pass --deny-warnings).

See the difference

Before
Launch partyDec 2, 2026
new Date("2026-12-02")
After
Launch partyDec 2, 2026
Temporal.PlainDate.from("2026-12-02")

What doesn't work

4 findings

What works

No findings

Details

Use Temporal instead of Date. Temporal is immutable, counts months from 1, keeps a moment in time (Instant), a moment in a zone (ZonedDateTime) and a calendar date (PlainDate) apart, and parses strings the same way everywhere.

There is no autofix: which Temporal type replaces a Date depends on what it means. Each message names the replacement for the pattern and the trap it avoids.

Code Message points to
new Date() Temporal.Now.instant(), Temporal.Now.zonedDateTimeISO(), Temporal.Now.plainDateISO()
new Date("2026-12-02") Parsed as UTC midnight, can show the previous day locally → Temporal.PlainDate.from(...)
new Date("2026-12-02T10:00") Parsed in the local zone → Temporal.PlainDateTime.from(...) / ZonedDateTime.from(...)
new Date(2026, 0, 15) Months count from 0 → Temporal.PlainDate.from({ year: 2026, month: 1, day: 15 }) (with your literals)
new Date(ms) Temporal.Instant.fromEpochMilliseconds(ms)
Date(), Date.parse(), Date.UTC() Temporal.Now…toString(), Temporal.Instant.from(), ZonedDateTime with timeZone: "UTC"
: Date (props, interfaces, tuples, …) Pick Instant, ZonedDateTime, PlainDate or PlainDateTime
x instanceof Date instanceof Temporal.Instant / …

Not reported:

  • Date.now(): just a number, fine for timings and cache keys. Report it with allowDateNow: false.
  • Converting back at a boundary: new Date(instant.epochMilliseconds).
  • A local Date (imported, class, type alias).
  • Files in ignore, e.g. database code where the ORM hands out Dates.

Safari and polyfills

Chrome / Edge 144+, Firefox 139+ and Node 26+ ship Temporal. Stable Safari, and with it every browser on iOS, doesn’t yet, so browser code needs a polyfill (temporal-polyfill is small; @js-temporal/polyfill is the reference implementation, about 100KB gzipped).

With source, the global Temporal is reported and the autofix adds the import:

Comparing Temporal values

a < b throws a TypeError for Temporal objects (their valueOf throws on purpose), and a === b only compares identity. Use Temporal.PlainDate.compare(a, b) and a.equals(b). This rule doesn’t check comparisons yet.

Option Default
source unset: the global Temporal is fine
allowDateNow true
ignore []: file globs relative to the nearest package.json; see monorepos

See also prefer-temporal-over-libraries.

Esc