Skip to content

Fix toLocaleString timeZoneName returning full name instead of abbreviation#2330

Merged
lahma merged 4 commits into
mainfrom
copilot/evaluate-latest-comment
Mar 18, 2026
Merged

Fix toLocaleString timeZoneName returning full name instead of abbreviation#2330
lahma merged 4 commits into
mainfrom
copilot/evaluate-latest-comment

Conversation

Copilot AI commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

toLocaleString with timeZoneName: 'short' was returning the full .NET timezone name (e.g., "Eastern Standard Time") instead of the proper IANA abbreviation ("EST"/"EDT"). The same issue affected timeStyle: 'full'/'long' and timeZoneName: 'long', which always returned the standard name regardless of DST.

Root Cause

GetTimeZoneDisplayName in JsDateTimeFormat had a broken fallback for the no-explicit-timezone case:

// Before: always standard name, always TimeZoneInfo.Local, never DST-aware
return longName ? TimeZoneInfo.Local.StandardName : TimeZoneInfo.Local.Id;

Three bugs in one line:

  • Used TimeZoneInfo.Local instead of the engine's configured default timezone
  • No DST check — always returned StandardName even during daylight saving time
  • Short name returned the Windows timezone ID ("Eastern Standard Time"), not an abbreviation

Fix

Replaced the fallback with proper logic mirroring the explicit-timezone path:

var defaultTz = _engine.Options.TimeSystem.DefaultTimeZone;
// DST check (consistent with TimeZone != null path)
defaultIsDst = defaultTz.IsDaylightSavingTime(DateTime.SpecifyKind(utcDateTime, DateTimeKind.Utc));

// Convert Windows ID → IANA for CLDR lookup (e.g. "Eastern Standard Time" → "America/New_York")
#if NET6_0_OR_GREATER
if (!defaultTz.HasIanaId && TimeZoneInfo.TryConvertWindowsIdToIanaId(defaultTzId, out var defaultIanaId))
    defaultTzId = defaultIanaId;
#endif

// CLDR metazone data returns "EDT"/"EST", "Eastern Daylight Time"/"Eastern Standard Time", etc.
var defaultCldrName = Data.MetaZoneData.GetDisplayName(defaultTzId, defaultIsDst, longName, generic);

Result:

new Date(2022, 6, 4).toLocaleString('en-US', { timeZoneName: 'short' })
// Before: "7/4/2022, 12:00:00 AM Eastern Standard Time"
// After:  "7/4/2022, 12:00:00 AM EDT"

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Co-authored-by: lahma <171892+lahma@users.noreply.github.com>
Copilot AI changed the title [WIP] Evaluate latest comment for completeness Fix toLocaleString timeZoneName returning full name instead of abbreviation Mar 16, 2026
Copilot AI requested a review from lahma March 16, 2026 21:00
@lahma
lahma marked this pull request as ready for review March 16, 2026 21:03
@lahma

lahma commented Mar 18, 2026

Copy link
Copy Markdown
Collaborator

@copilot check windows ci failure

…up table

Co-authored-by: lahma <171892+lahma@users.noreply.github.com>

Copilot AI commented Mar 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot check windows ci failure

The Windows CI failure was in Jint.Tests.exe (net472): ToLocaleStringUsesShortTimeZoneAbbreviation failed because TimeZoneInfo.TryConvertWindowsIdToIanaId isn't available on .NET Framework 4.7.2 (it's wrapped in #if NET6_0_OR_GREATER). Without it, the Windows timezone ID "Eastern Standard Time" wasn't converted to "America/New_York" before the CLDR lookup, so the lookup failed and the fallback returned the wrong value.

Fixed in a13db30 by adding Windows timezone ID aliases directly to the IanaToMetaZone dictionary in MetaZoneData.cs (covering ~70 common Windows timezone IDs). This makes the CLDR lookup work on all .NET versions. Also fixed the final fallback for short names to be DST-aware when the timezone ID has no '/' (as Windows IDs do).

Copilot AI requested a review from lahma March 18, 2026 07:07
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