Skip to content

Disallow 'timeZone' option in Temporal.ZonedDateTime.prototype.toLocaleString - #65391

Closed
Sai krishna Bodapati (bodapatisaikrishna) wants to merge 1 commit into
microsoft:mainfrom
bodapatisaikrishna:fix/64227-zoneddatetime-tolocalestring-timezone-option
Closed

Sai krishna Bodapati (bodapatisaikrishna) wants to merge 1 commit into
microsoft:mainfrom
bodapatisaikrishna:fix/64227-zoneddatetime-tolocalestring-timezone-option

Conversation

@bodapatisaikrishna

Copy link
Copy Markdown

Under ECMA-402 Temporal, Temporal.ZonedDateTime.prototype.toLocaleString strictly disallows passing a timeZone option because the receiver's time zone is always used (engines throw a TypeError if provided).

This PR introduces Temporal.ZonedDateTimeToLocaleStringOptions extending Omit<Intl.DateTimeFormatOptions, "timeZone">, updates ZonedDateTime.prototype.toLocaleString() to use it, and updates compiler baselines.

Fixes #64227

(Note: Authored with AI assistance and verified locally against the compiler baseline suite.)

…leString

Per ECMA-402 Temporal, ZonedDateTime.prototype.toLocaleString rejects
the timeZone option because the receiver's timeZoneId is always used.
Introduce ZonedDateTimeToLocaleStringOptions extending
Omit<Intl.DateTimeFormatOptions, "timeZone"> and update the compiler baselines.

Fixes microsoft#64227

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Copilot was unable to run its full agentic suite in this review.

Copilot review overview

1 open issue
What changed in this PR

Updates Temporal ZonedDateTime#toLocaleString typing to disallow the timeZone option (aligning with the intended API constraints) and adds regression coverage for #64227.

Changes:

  • Introduced Temporal.ZonedDateTimeToLocaleStringOptions as Omit<Intl.DateTimeFormatOptions, "timeZone">.
  • Updated ZonedDateTime#toLocaleString signature to use the new options type.
  • Added compiler test cases + updated baselines to validate the new typing and expected errors.
File Description
tsc/​testdata/​tests/​cases/​compiler/​temporal.ts Adds regression calls for ZonedDateTime#toLocaleString (including timeZone) to lock in behavior.
tsc/​internal/​bundled/​libs/​lib.esnext.temporal.d.ts Introduces a dedicated options type and updates toLocaleString to exclude timeZone.
tsc/​testdata/​baselines/​reference/​compiler/​temporal.types Baseline updates reflecting the new toLocaleString options type.
tsc/​testdata/​baselines/​reference/​compiler/​temporal.symbols Baseline updates for symbol binding of the new test block.
tsc/​testdata/​baselines/​reference/​compiler/​temporal.js Baseline updates for JS emit including the new test block.
tsc/​testdata/​baselines/​reference/​compiler/​temporal.errors.txt Baseline updates capturing new expected TS2353 errors for timeZone in options.

Review effort: Lite

Comment on lines +1829 to +1830
zdt.toLocaleString(undefined, { timeZone: "Europe/Berlin" });
zdt.toLocaleString("en-US", { timeZone: "Europe/Berlin" });
@typescript-automation typescript-automation Bot added For Backlog Bug PRs that fix a backlog bug For Milestone Bug PRs that fix a bug with a specific milestone and removed For Milestone Bug PRs that fix a bug with a specific milestone For Backlog Bug PRs that fix a backlog bug labels Nov 10, 2026
@RyanCavanaugh

Copy link
Copy Markdown
Member

Closing in favor of the most recent PR to fix this issue

@github-project-automation github-project-automation Bot moved this from Not started to Done in PR Backlog Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Milestone Bug PRs that fix a bug with a specific milestone

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

The options arg of Temporal.ZonedDateTime.prototype.toLocaleString() currently accepts "illegal" option timeZone

3 participants