Skip to content

Commit b0cd70b

Browse files
committed
Fix lazy initialization for Minimal Globalization Data
1 parent 25ea2bb commit b0cd70b

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,26 @@ private static string GetUtcFullDisplayName(string timeZoneId, string standardDi
4848
}
4949
#pragma warning restore IDE0060
5050

51+
private static void GetStandardDisplayName(string timeZoneId, ref string? displayName)
52+
{
53+
// Determine the culture to use
54+
CultureInfo uiCulture = CultureInfo.CurrentUICulture;
55+
if (uiCulture.Name.Length == 0)
56+
uiCulture = CultureInfo.GetCultureInfo(FallbackCultureName); // ICU doesn't work nicely with InvariantCulture
57+
58+
GetDisplayName(timeZoneId, Interop.Globalization.TimeZoneDisplayNameType.Standard, uiCulture.Name, ref displayName);
59+
}
60+
61+
private static void GetDaylightDisplayName(string timeZoneId, ref string? displayName)
62+
{
63+
// Determine the culture to use
64+
CultureInfo uiCulture = CultureInfo.CurrentUICulture;
65+
if (uiCulture.Name.Length == 0)
66+
uiCulture = CultureInfo.GetCultureInfo(FallbackCultureName); // ICU doesn't work nicely with InvariantCulture
67+
68+
GetDisplayName(timeZoneId, Interop.Globalization.TimeZoneDisplayNameType.DaylightSavings, uiCulture.Name, ref displayName);
69+
}
70+
5171
// Helper function that retrieves various forms of time zone display names from ICU
5272
private static unsafe void GetDisplayName(string timeZoneId, Interop.Globalization.TimeZoneDisplayNameType nameType, string uiCulture, ref string? displayName)
5373
{
@@ -96,8 +116,13 @@ private static unsafe void GetDisplayName(string timeZoneId, Interop.Globalizati
96116
}
97117

98118
// Helper function that builds the value backing the DisplayName field from globalization data.
99-
private static void GetFullValueForDisplayNameField(string timeZoneId, TimeSpan baseUtcOffset, CultureInfo uiCulture, ref string? displayName)
119+
private static void GetFullValueForDisplayNameField(string timeZoneId, TimeSpan baseUtcOffset, ref string? displayName)
100120
{
121+
// Determine the culture to use
122+
CultureInfo uiCulture = CultureInfo.CurrentUICulture;
123+
if (uiCulture.Name.Length == 0)
124+
uiCulture = CultureInfo.GetCultureInfo(FallbackCultureName); // ICU doesn't work nicely with InvariantCulture
125+
101126
// There are a few diffent ways we might show the display name depending on the data.
102127
// The algorithm used below should avoid duplicating the same words while still achieving the
103128
// goal of providing a unique, discoverable, and intuitive name.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ namespace System
66
public sealed partial class TimeZoneInfo
77
{
88
#pragma warning disable IDE0060
9+
static partial void GetFullValueForDisplayNameField(string timeZoneId, TimeSpan baseUtcOffset, ref string? displayName);
10+
11+
static partial void GetStandardDisplayName(string timeZoneId, ref string? displayName);
12+
13+
static partial void GetDaylightDisplayName(string timeZoneId, ref string? displayName);
14+
915
private static string GetUtcStandardDisplayName()
1016
{
1117
// For this target, be consistent with other time zone display names that use an abbreviation.

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

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,7 @@ public AdjustmentRule[] GetAdjustmentRules()
231231
if (GlobalizationMode.Invariant)
232232
return displayName;
233233

234-
// Determine the culture to use
235-
CultureInfo uiCulture = CultureInfo.CurrentUICulture;
236-
if (uiCulture.Name.Length == 0)
237-
uiCulture = CultureInfo.GetCultureInfo(FallbackCultureName); // ICU doesn't work nicely with InvariantCulture
238-
239-
GetFullValueForDisplayNameField(Id, BaseUtcOffset, uiCulture, ref displayName);
234+
GetFullValueForDisplayNameField(Id, BaseUtcOffset, ref displayName);
240235

241236
return displayName;
242237
}
@@ -250,11 +245,7 @@ public AdjustmentRule[] GetAdjustmentRules()
250245
if (GlobalizationMode.Invariant)
251246
return standardDisplayName;
252247

253-
CultureInfo uiCulture = CultureInfo.CurrentUICulture;
254-
if (uiCulture.Name.Length == 0)
255-
uiCulture = CultureInfo.GetCultureInfo(FallbackCultureName); // ICU doesn't work nicely with InvariantCulture
256-
257-
GetDisplayName(Id, Interop.Globalization.TimeZoneDisplayNameType.Standard, uiCulture.Name, ref standardDisplayName);
248+
GetStandardDisplayName(Id, ref standardDisplayName);
258249

259250
return standardDisplayName;
260251
}
@@ -268,12 +259,7 @@ public AdjustmentRule[] GetAdjustmentRules()
268259
if (GlobalizationMode.Invariant)
269260
return daylightDisplayName;
270261

271-
// Determine the culture to use
272-
CultureInfo uiCulture = CultureInfo.CurrentUICulture;
273-
if (uiCulture.Name.Length == 0)
274-
uiCulture = CultureInfo.GetCultureInfo(FallbackCultureName); // ICU doesn't work nicely with InvariantCulture
275-
276-
GetDisplayName(Id, Interop.Globalization.TimeZoneDisplayNameType.DaylightSavings, uiCulture.Name, ref daylightDisplayName);
262+
GetDaylightDisplayName(Id, ref daylightDisplayName);
277263

278264
return daylightDisplayName;
279265
}

0 commit comments

Comments
 (0)