Skip to content

Fix TimeZone Names #106038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ public AdjustmentRule[] GetAdjustmentRules()
return rulesList.ToArray();
}

private string NameLookupId =>
HasIanaId ? Id :
(_equivalentZones is not null && _equivalentZones.Count > 0 ? _equivalentZones[0].Id : (GetAlternativeId(Id, out _) ?? Id));

private string? PopulateDisplayName()
{
if (IsUtcAlias(Id))
Expand All @@ -239,7 +243,7 @@ public AdjustmentRule[] GetAdjustmentRules()
if (!GlobalizationMode.Hybrid)
return displayName;
#endif
GetFullValueForDisplayNameField(Id, BaseUtcOffset, ref displayName);
GetFullValueForDisplayNameField(NameLookupId, BaseUtcOffset, ref displayName);

return displayName;
}
Expand All @@ -257,7 +261,7 @@ public AdjustmentRule[] GetAdjustmentRules()
if (!GlobalizationMode.Hybrid)
return standardDisplayName;
#endif
GetStandardDisplayName(Id, ref standardDisplayName);
GetStandardDisplayName(NameLookupId, ref standardDisplayName);

return standardDisplayName;
}
Expand All @@ -275,7 +279,7 @@ public AdjustmentRule[] GetAdjustmentRules()
if (!GlobalizationMode.Hybrid)
return daylightDisplayName;
#endif
GetDaylightDisplayName(Id, ref daylightDisplayName);
GetDaylightDisplayName(NameLookupId, ref daylightDisplayName);

return daylightDisplayName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3222,6 +3222,33 @@ public static void TestCustomTimeZonesWithNullNames()
Assert.Equal(string.Empty, custom.DisplayName);
}

[InlineData("Eastern Standard Time", "America/New_York")]
[InlineData("Central Standard Time", "America/Chicago")]
[InlineData("Mountain Standard Time", "America/Denver")]
[InlineData("Pacific Standard Time", "America/Los_Angeles")]
[ConditionalTheory(nameof(SupportICUAndRemoteExecution))]
public static void TestTimeZoneNames(string windowsId, string ianaId)
{
RemoteExecutor.Invoke(static (wId, iId) =>
{
TimeZoneInfo info1, info2;
if (PlatformDetection.IsWindows)
{
info1 = TimeZoneInfo.FindSystemTimeZoneById(iId);
info2 = TimeZoneInfo.FindSystemTimeZoneById(wId);
}
else
{
info1 = TimeZoneInfo.FindSystemTimeZoneById(wId);
info2 = TimeZoneInfo.FindSystemTimeZoneById(iId);
}

Assert.Equal(info1.StandardName, info2.StandardName);
Assert.Equal(info1.DaylightName, info2.DaylightName);
Assert.Equal(info1.DisplayName, info2.DisplayName);
}, windowsId, ianaId).Dispose();
}

private static bool IsEnglishUILanguage => CultureInfo.CurrentUICulture.Name.Length == 0 || CultureInfo.CurrentUICulture.TwoLetterISOLanguageName == "en";

private static bool IsEnglishUILanguageAndRemoteExecutorSupported => IsEnglishUILanguage && RemoteExecutor.IsSupported;
Expand Down
Loading