Skip to content

Fix UTC relative day names - #194

Merged
chase-manning merged 1 commit into
felixge:masterfrom
n0liu:fix-utc-relative-day-names
Oct 24, 2026
Merged

chase-manning merged 1 commit into
felixge:masterfrom
n0liu:fix-utc-relative-day-names

Conversation

@n0liu

@n0liu n0liu commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

When the local calendar day differs from UTC, DDD and DDDD calculate yesterday and tomorrow using getUTCDate() followed by the local setDate(). This can lose the relative label or apply it to a date two days away.

For example, with TZ=America/Los_Angeles and the clock fixed at 2024-01-01T00:30:00Z, formatting 2023-12-31T00:30:00Z with UTC:DDDD returns Sunday instead of Yesterday.

Use setUTCDate() when the selected getters use UTC, keeping the local setter for local mode. This covers the UTC: and GMT: prefixes and the explicit UTC argument.

Validation:

  • Added six deterministic tests using a fixed clock in separate timezone processes. They cover local dates ahead of and behind UTC, month/year boundaries, ordinary weekday fallbacks, and local dates across both DST transitions.
  • Four of the new tests fail before the fix; the two local-mode checks already pass.
  • npm test: build succeeds and all 159 tests pass on Node.js 22.21.1.
  • Compared the compiled baseline and patched versions over the existing benchmark masks plus the relative-day masks, using 50,000 calls and five alternating rounds. Relative-day timings were within 3% in this run. The existing benchmark entry point uses CommonJS in this ESM package, so the comparison used an ESM adapter.

@chase-manning
chase-manning merged commit 4d7ed09 into felixge:master Oct 24, 2026
@chase-manning

Copy link
Copy Markdown
Collaborator

Thanks for the PR 🙏

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