Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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