Skip to content

Commit

Permalink
Fix TimeZone Names (#106056)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarekgh authored Aug 8, 2024
1 parent 58d9176 commit 5807052
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,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 @@ -231,7 +235,7 @@ public AdjustmentRule[] GetAdjustmentRules()
if (GlobalizationMode.Invariant)
return displayName;

GetFullValueForDisplayNameField(Id, BaseUtcOffset, ref displayName);
GetFullValueForDisplayNameField(NameLookupId, BaseUtcOffset, ref displayName);

return displayName;
}
Expand All @@ -245,7 +249,7 @@ public AdjustmentRule[] GetAdjustmentRules()
if (GlobalizationMode.Invariant)
return standardDisplayName;

GetStandardDisplayName(Id, ref standardDisplayName);
GetStandardDisplayName(NameLookupId, ref standardDisplayName);

return standardDisplayName;
}
Expand All @@ -259,7 +263,7 @@ public AdjustmentRule[] GetAdjustmentRules()
if (GlobalizationMode.Invariant)
return daylightDisplayName;

GetDaylightDisplayName(Id, ref daylightDisplayName);
GetDaylightDisplayName(NameLookupId, ref daylightDisplayName);

return daylightDisplayName;
}
Expand Down
26 changes: 26 additions & 0 deletions src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3211,6 +3211,32 @@ 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

0 comments on commit 5807052

Please sign in to comment.