Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/6.0] Fix TimeZoneInfo.HasIanaId when using Local Time Zone #58414

Merged
merged 1 commit into from
Aug 31, 2021
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 @@ -85,7 +85,8 @@ private TimeZoneInfo CreateLocal()
timeZone._standardDisplayName,
timeZone._daylightDisplayName,
timeZone._adjustmentRules,
disableDaylightSavingTime: false);
disableDaylightSavingTime: false,
timeZone.HasIanaId);

_localTimeZone = timeZone;
}
Expand Down Expand Up @@ -1954,7 +1955,7 @@ private static TimeZoneInfoResult TryGetTimeZoneFromLocalMachine(string id, bool
else
{
value = new TimeZoneInfo(match!._id, match._baseUtcOffset, match._displayName, match._standardDisplayName,
match._daylightDisplayName, match._adjustmentRules, disableDaylightSavingTime: false);
match._daylightDisplayName, match._adjustmentRules, disableDaylightSavingTime: false, match.HasIanaId);
}
}
else
Expand Down
20 changes: 20 additions & 0 deletions src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2642,13 +2642,33 @@ public static void UsingAlternativeTimeZoneIdsTest(string windowsId, string iana
}

public static bool SupportIanaNamesConversion => PlatformDetection.IsNotBrowser && PlatformDetection.ICUVersion.Major >= 52;
public static bool SupportIanaNamesConversionAndRemoteExecution => SupportIanaNamesConversion && RemoteExecutor.IsSupported;

// This test is executed using the remote execution because it needs to run before creating the time zone cache to ensure testing with that state.
// There are already other tests that test after creating the cache.
[ConditionalFact(nameof(SupportIanaNamesConversionAndRemoteExecution))]
public static void IsIanaIdWithNotCacheTest()
{
RemoteExecutor.Invoke(() =>
{
Assert.Equal(!s_isWindows || TimeZoneInfo.Local.Id.Equals("Utc", StringComparison.OrdinalIgnoreCase), TimeZoneInfo.Local.HasIanaId);

TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
Assert.False(tzi.HasIanaId);

tzi = TimeZoneInfo.FindSystemTimeZoneById("Europe/Berlin");
Assert.True(tzi.HasIanaId);
}).Dispose();
}

[ConditionalFact(nameof(SupportIanaNamesConversion))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/52072", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
public static void IsIanaIdTest()
{
bool expected = !s_isWindows;

Assert.Equal((expected || TimeZoneInfo.Local.Id.Equals("Utc", StringComparison.OrdinalIgnoreCase)), TimeZoneInfo.Local.HasIanaId);

foreach (TimeZoneInfo tzi in TimeZoneInfo.GetSystemTimeZones())
{
Assert.True((expected || tzi.Id.Equals("Utc", StringComparison.OrdinalIgnoreCase)) == tzi.HasIanaId, $"`{tzi.Id}` has wrong IANA Id indicator");
Expand Down