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

Fix TimeZoneInfo.Equals and TimeZoneInfo.HasSameRules #88869

Merged
merged 7 commits into from
Jul 16, 2023
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 @@ -934,9 +934,9 @@ public bool HasSameRules(TimeZoneInfo other)
AdjustmentRule[]? currentRules = _adjustmentRules;
AdjustmentRule[]? otherRules = other._adjustmentRules;

if (currentRules is null || otherRules is null)
if (currentRules is null && otherRules is null)
{
return currentRules == otherRules;
return true;
}

return currentRules.AsSpan().SequenceEqual(otherRules);
Expand Down
13 changes: 6 additions & 7 deletions src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2432,17 +2432,16 @@ public static void TimeZoneDisplayNames_Unix(TimeZoneInfo timeZone)
}
}

[Fact]
[PlatformSpecific(~TestPlatforms.Windows & ~TestPlatforms.Browser)]
private static bool SupportICUWithUtcAlias => PlatformDetection.IsIcuGlobalization && PlatformDetection.IsNotAppleMobile && PlatformDetection.IsNotBrowser;

[ConditionalFact(nameof(SupportICUWithUtcAlias))]
public static void UtcAliases_MapToUtc()
{
TimeZoneInfo.AdjustmentRule[] expectedAdjustmentRules = TimeZoneInfo.Utc.GetAdjustmentRules();

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

Expand Down