diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.FullGlobalizationData.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.FullGlobalizationData.Unix.cs index 5a80d7b448649d..e0c284b6c53522 100644 --- a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.FullGlobalizationData.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.FullGlobalizationData.Unix.cs @@ -24,6 +24,11 @@ public sealed partial class TimeZoneInfo // Main function that is called during construction to populate the three display names private static void TryPopulateTimeZoneDisplayNamesFromGlobalizationData(string timeZoneId, TimeSpan baseUtcOffset, ref string? standardDisplayName, ref string? daylightDisplayName, ref string? displayName) { + if (GlobalizationMode.Invariant) + { + return; + } + // Determine the culture to use CultureInfo uiCulture = CultureInfo.CurrentUICulture; if (uiCulture.Name.Length == 0) diff --git a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs index f560cf7d10ae4a..a61f6a347c296c 100644 --- a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs +++ b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs @@ -2541,6 +2541,30 @@ public static void NJulianRuleTest(string posixRule, int dayNumber, int monthNum } } + [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] + public static void TimeZoneInfo_LocalZoneWithInvariantMode() + { + string hostTZId = TimeZoneInfo.Local.Id; + + ProcessStartInfo psi = new ProcessStartInfo() { UseShellExecute = false }; + psi.Environment.Add("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", PlatformDetection.IsInvariantGlobalization ? "0" : "1"); + + RemoteExecutor.Invoke((tzId, hostIsRunningInInvariantMode) => + { + bool hostInvariantMode = bool.Parse(hostIsRunningInInvariantMode); + + if (!hostInvariantMode) + { + // If hostInvariantMode is false, means the child process should enable the globalization invariant mode. + // We validate here that by trying to create a culture which should throws in such mode. + Assert.Throws(() => CultureInfo.GetCultureInfo("en-US")); + } + + Assert.Equal(tzId, TimeZoneInfo.Local.Id); + + }, hostTZId, PlatformDetection.IsInvariantGlobalization.ToString(), new RemoteInvokeOptions { StartInfo = psi}).Dispose(); + } + [Fact] public static void TimeZoneInfo_DaylightDeltaIsNoMoreThan12Hours() {