Skip to content

Commit

Permalink
[libs][Unix] Fix UTC alias lookup (#88641)
Browse files Browse the repository at this point in the history
  • Loading branch information
RenderMichael authored Jul 13, 2023
1 parent 3eb6eef commit 218d2ef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ private static bool IsUtcAlias (string id)
case 69: // e
case 101: // E
return string.Equals(id, "Etc/UTC", StringComparison.OrdinalIgnoreCase) ||
string.Equals(id, "Etc/UCT", StringComparison.OrdinalIgnoreCase) ||
string.Equals(id, "Etc/Universal", StringComparison.OrdinalIgnoreCase) ||
string.Equals(id, "Etc/UTC", StringComparison.OrdinalIgnoreCase) ||
string.Equals(id, "Etc/Zulu", StringComparison.OrdinalIgnoreCase);
case 85: // u
case 117: // U
Expand Down
22 changes: 22 additions & 0 deletions src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2334,6 +2334,14 @@ public static IEnumerable<object[]> SystemTimeZonesTestData()
yield return new object[] { tz };
}
}

if (!PlatformDetection.IsBrowser)
{
foreach (string alias in s_UtcAliases)
{
yield return new object[] { TimeZoneInfo.FindSystemTimeZoneById(alias) };
}
}
}
}

Expand Down Expand Up @@ -2424,6 +2432,20 @@ public static void TimeZoneDisplayNames_Unix(TimeZoneInfo timeZone)
}
}

[Fact]
[PlatformSpecific(~TestPlatforms.Windows & ~TestPlatforms.Browser)]
public static void UtcAliases_MapToUtc()
{
TimeZoneInfo.AdjustmentRule[] expectedAdjustmentRules = TimeZoneInfo.Utc.GetAdjustmentRules();

foreach (var alias in s_UtcAliases)
{
TimeZoneInfo actualUtc = TimeZoneInfo.FindSystemTimeZoneById(alias);
Assert.Equal(TimeZoneInfo.Utc.BaseUtcOffset, actualUtc.BaseUtcOffset);
Assert.Equal(expectedAdjustmentRules, actualUtc.GetAdjustmentRules());
}
}

[ActiveIssue("https://github.com/dotnet/runtime/issues/19794", TestPlatforms.AnyUnix)]
[Theory]
[MemberData(nameof(SystemTimeZonesTestData))]
Expand Down

0 comments on commit 218d2ef

Please sign in to comment.