Skip to content

Commit d57f4af

Browse files
authored
Fix TimeZone Names (#106038)
1 parent 4e270d9 commit d57f4af

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ public AdjustmentRule[] GetAdjustmentRules()
224224
return rulesList.ToArray();
225225
}
226226

227+
private string NameLookupId =>
228+
HasIanaId ? Id :
229+
(_equivalentZones is not null && _equivalentZones.Count > 0 ? _equivalentZones[0].Id : (GetAlternativeId(Id, out _) ?? Id));
230+
227231
private string? PopulateDisplayName()
228232
{
229233
if (IsUtcAlias(Id))
@@ -239,7 +243,7 @@ public AdjustmentRule[] GetAdjustmentRules()
239243
if (!GlobalizationMode.Hybrid)
240244
return displayName;
241245
#endif
242-
GetFullValueForDisplayNameField(Id, BaseUtcOffset, ref displayName);
246+
GetFullValueForDisplayNameField(NameLookupId, BaseUtcOffset, ref displayName);
243247

244248
return displayName;
245249
}
@@ -257,7 +261,7 @@ public AdjustmentRule[] GetAdjustmentRules()
257261
if (!GlobalizationMode.Hybrid)
258262
return standardDisplayName;
259263
#endif
260-
GetStandardDisplayName(Id, ref standardDisplayName);
264+
GetStandardDisplayName(NameLookupId, ref standardDisplayName);
261265

262266
return standardDisplayName;
263267
}
@@ -275,7 +279,7 @@ public AdjustmentRule[] GetAdjustmentRules()
275279
if (!GlobalizationMode.Hybrid)
276280
return daylightDisplayName;
277281
#endif
278-
GetDaylightDisplayName(Id, ref daylightDisplayName);
282+
GetDaylightDisplayName(NameLookupId, ref daylightDisplayName);
279283

280284
return daylightDisplayName;
281285
}

src/libraries/System.Runtime/tests/System.Runtime.Tests/System/TimeZoneInfoTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,6 +3222,33 @@ public static void TestCustomTimeZonesWithNullNames()
32223222
Assert.Equal(string.Empty, custom.DisplayName);
32233223
}
32243224

3225+
[InlineData("Eastern Standard Time", "America/New_York")]
3226+
[InlineData("Central Standard Time", "America/Chicago")]
3227+
[InlineData("Mountain Standard Time", "America/Denver")]
3228+
[InlineData("Pacific Standard Time", "America/Los_Angeles")]
3229+
[ConditionalTheory(nameof(SupportICUAndRemoteExecution))]
3230+
public static void TestTimeZoneNames(string windowsId, string ianaId)
3231+
{
3232+
RemoteExecutor.Invoke(static (wId, iId) =>
3233+
{
3234+
TimeZoneInfo info1, info2;
3235+
if (PlatformDetection.IsWindows)
3236+
{
3237+
info1 = TimeZoneInfo.FindSystemTimeZoneById(iId);
3238+
info2 = TimeZoneInfo.FindSystemTimeZoneById(wId);
3239+
}
3240+
else
3241+
{
3242+
info1 = TimeZoneInfo.FindSystemTimeZoneById(wId);
3243+
info2 = TimeZoneInfo.FindSystemTimeZoneById(iId);
3244+
}
3245+
3246+
Assert.Equal(info1.StandardName, info2.StandardName);
3247+
Assert.Equal(info1.DaylightName, info2.DaylightName);
3248+
Assert.Equal(info1.DisplayName, info2.DisplayName);
3249+
}, windowsId, ianaId).Dispose();
3250+
}
3251+
32253252
private static bool IsEnglishUILanguage => CultureInfo.CurrentUICulture.Name.Length == 0 || CultureInfo.CurrentUICulture.TwoLetterISOLanguageName == "en";
32263253

32273254
private static bool IsEnglishUILanguageAndRemoteExecutorSupported => IsEnglishUILanguage && RemoteExecutor.IsSupported;

0 commit comments

Comments
 (0)