Skip to content

fix: format dates with an unknown system timezone - #101

Open
pavel-klimov wants to merge 3 commits into
mainfrom
fix/unknown-system-timezone
Open

pavel-klimov wants to merge 3 commits into
mainfrom
fix/unknown-system-timezone

Conversation

@pavel-klimov

@pavel-klimov pavel-klimov commented Oct 16, 2026 •

Copy link
Copy Markdown

When the browser reports Etc/Unknown as its system time zone, formatting a date with z or zz throws InvalidZone and can break rendering.

Use the date's numeric UTC offset to format a localized time zone label through Intl, preserving the distinction between short and long names. Engines without support for offset time zones fall back to a numeric label such as GMT+03:00. Valid time zone names keep their existing formatting, and explicitly supplied invalid time zones are still rejected during date creation.

Added regression tests for an unknown system time zone, French labels, zero offset, engines without offset-zone support, and explicit time zones. Offset formatting reuses the same helper as the Z token.

Scope

This PR handles date formatting only. guessUserTimeZone() and the timeZone() getter still return the zone reported by Intl, which may be an invalid ID such as Etc/Unknown. Their JSDoc now documents that callers must validate the result with isValidTimeZone before passing it to dateTime, the timeZone setter, timeZoneOffset, or settings.setDefaultTimeZone. Normalizing these public API results and handling time zones sent to a server are outside this change.

Tests

  • npm test -- --runInBand — 526 tests passed on Node 18 and Node 24
  • npm run typecheck
  • npm run lint — passes with 7 existing warnings in unchanged files

@korvin89 korvin89 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI generated

This review was done with AI assistance. I validated every comment myself, but the wording — including the points I found myself — was written by the AI.

Severity legend

  • 🔴 blocker — should be fixed before merge.
  • 🟠 should-fix — a real problem; worth fixing before or right after merge. If you can't get to it now, please open an issue and leave a comment linking it.
  • 🔵 nit — minor; author's discretion.
  • ❓ question — I need more context; not necessarily a defect.

Findings outside the diff

  • src/timeZone/timeZone.ts:9 — 🟠 should-fix — This PR fixes the symptom in format.ts, but the source is guessUserTimeZone() (public export in src/index.ts:9) and the timeZone() getter (src/dateTime/dateTime.ts:138), which still return Etc/Unknown. Common "read the zone and pass it back" flows still throw InvalidZone: date.timeZone(date.timeZone()), dateTime({timeZone: guessUserTimeZone()}), settings.setDefaultTimeZone(guessUserTimeZone()). timeZoneOffset(guessUserTimeZone(), ts) returns NaN.

If handling these paths is intentionally out of scope for this PR, please state that in the PR description and document the behavior in the JSDoc of guessUserTimeZone (and the timeZone() getter): the returned value may be an invalid zone ID such as Etc/Unknown and should be validated with isValidTimeZone before being passed back. Otherwise, normalize in guessUserTimeZone itself so the other paths stop throwing as well.

Comment thread src/dateTime/format.ts Resolved
Comment thread src/dateTime/__tests__/format.ts Resolved
Comment thread src/dateTime/__tests__/format.ts Resolved
Comment thread src/dateTime/format.ts Resolved
@pavel-klimov
pavel-klimov requested a review from korvin89 October 19, 2026 15:31
@korvin89

korvin89 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

@ValeraS could u take a look please?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants