Skip to content

Commit

Permalink
[release/6.0] Fix Time Zone when running with Globalization Invariant…
Browse files Browse the repository at this point in the history
… Mode (#59727)
  • Loading branch information
github-actions[bot] committed Sep 29, 2021
1 parent b2b0619 commit 9e0a252
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CultureNotFoundException>(() => 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()
{
Expand Down

0 comments on commit 9e0a252

Please sign in to comment.