From bf3b43b1b1a64c33f3d60a649c0c0312fc942d70 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Thu, 13 Jul 2023 16:31:02 -0400 Subject: [PATCH 1/7] Fix `TimeZoneInfo.HasSameRules` * Equates null and empty adjustment rules --- .../System.Private.CoreLib/src/System/TimeZoneInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.cs b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.cs index 583212906e68c..0be2c6282eef9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.cs @@ -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); From d57b4030d8855e7eca949c5b84f4a87ce1127359 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Thu, 13 Jul 2023 16:38:10 -0400 Subject: [PATCH 2/7] Add a test for UTC equality --- .../System.Runtime/tests/System/TimeZoneInfoTests.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs index 386ca83b3771f..7bdb017659dc4 100644 --- a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs +++ b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs @@ -2446,6 +2446,16 @@ public static void UtcAliases_MapToUtc() } } + [Fact] + public static void UtcAliases_AreEqualToUtc() + { + foreach (string alias in s_UtcAliases) + { + TimeZoneInfo actualUtc = TimeZoneInfo.FindSystemTimeZoneById(alias); + Assert.Equal(TimeZoneInfo.Utc, actualUtc); + } + } + [ActiveIssue("https://github.com/dotnet/runtime/issues/19794", TestPlatforms.AnyUnix)] [Theory] [MemberData(nameof(SystemTimeZonesTestData))] From fec57b984d87538af18c3737d8f47d41580b47bf Mon Sep 17 00:00:00 2001 From: RenderMichael Date: Fri, 14 Jul 2023 02:44:02 -0400 Subject: [PATCH 3/7] Replace UtcAliases_MapToUtc instead of new test --- .../tests/System/TimeZoneInfoTests.cs | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs index 7bdb017659dc4..22cdd8db83dff 100644 --- a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs +++ b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs @@ -2432,27 +2432,14 @@ public static void TimeZoneDisplayNames_Unix(TimeZoneInfo timeZone) } } - [Fact] - [PlatformSpecific(~TestPlatforms.Windows & ~TestPlatforms.Browser)] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsIcuGlobalization))] 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()); - } - } - - [Fact] - public static void UtcAliases_AreEqualToUtc() { foreach (string alias in s_UtcAliases) { TimeZoneInfo actualUtc = TimeZoneInfo.FindSystemTimeZoneById(alias); - Assert.Equal(TimeZoneInfo.Utc, actualUtc); + Assert.True(TimeZoneInfo.Utc.HasSameRules(actualUtc)); + Assert.True(actualUtc.HasSameRules(TimeZoneInfo.Utc)); } } From d1809938e61dafdcced88864c86d6eba2929abcf Mon Sep 17 00:00:00 2001 From: Michael Render Date: Fri, 14 Jul 2023 09:18:59 -0400 Subject: [PATCH 4/7] Only run test on supported platforms --- src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs index 22cdd8db83dff..3de1b8e0507f4 100644 --- a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs +++ b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs @@ -2433,6 +2433,7 @@ public static void TimeZoneDisplayNames_Unix(TimeZoneInfo timeZone) } [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsIcuGlobalization))] + [PlatformSpecific(~TestPlatforms.Browser | ~TestPlatforms.iOS | ~TestPlatforms.tvOS)] public static void UtcAliases_MapToUtc() { foreach (string alias in s_UtcAliases) From fe52806791dc6c3c3bdce9e8fa09cd1a48c2662a Mon Sep 17 00:00:00 2001 From: Michael Render Date: Fri, 14 Jul 2023 15:09:44 -0400 Subject: [PATCH 5/7] Looks like ConditionalFact does not work alongsize PlatformSpecific --- .../System.Runtime/tests/System/TimeZoneInfoTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs index 3de1b8e0507f4..741c9bb06ee0f 100644 --- a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs +++ b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs @@ -2432,8 +2432,8 @@ public static void TimeZoneDisplayNames_Unix(TimeZoneInfo timeZone) } } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsIcuGlobalization))] - [PlatformSpecific(~TestPlatforms.Browser | ~TestPlatforms.iOS | ~TestPlatforms.tvOS)] + [Fact] + [PlatformSpecific(~TestPlatforms.Windows | ~TestPlatforms.Browser | ~TestPlatforms.iOS | ~TestPlatforms.tvOS)] public static void UtcAliases_MapToUtc() { foreach (string alias in s_UtcAliases) From a1ebf6253c4ce4b83735ecf5c08544363fe2171b Mon Sep 17 00:00:00 2001 From: Michael Render Date: Fri, 14 Jul 2023 16:44:49 -0400 Subject: [PATCH 6/7] Fix typo --- src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs index 741c9bb06ee0f..bbc2532e88b0c 100644 --- a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs +++ b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs @@ -2433,7 +2433,7 @@ public static void TimeZoneDisplayNames_Unix(TimeZoneInfo timeZone) } [Fact] - [PlatformSpecific(~TestPlatforms.Windows | ~TestPlatforms.Browser | ~TestPlatforms.iOS | ~TestPlatforms.tvOS)] + [PlatformSpecific(~TestPlatforms.Windows & ~TestPlatforms.Browser & ~TestPlatforms.iOS & ~TestPlatforms.tvOS)] public static void UtcAliases_MapToUtc() { foreach (string alias in s_UtcAliases) From 3ee3f85b40510529a1f4b37ee6a6578e627ce91e Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sun, 16 Jul 2023 15:17:33 -0400 Subject: [PATCH 7/7] PR feedback --- .../System.Runtime/tests/System/TimeZoneInfoTests.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs index bbc2532e88b0c..3f8f93536626f 100644 --- a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs +++ b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs @@ -2432,8 +2432,9 @@ public static void TimeZoneDisplayNames_Unix(TimeZoneInfo timeZone) } } - [Fact] - [PlatformSpecific(~TestPlatforms.Windows & ~TestPlatforms.Browser & ~TestPlatforms.iOS & ~TestPlatforms.tvOS)] + private static bool SupportICUWithUtcAlias => PlatformDetection.IsIcuGlobalization && PlatformDetection.IsNotAppleMobile && PlatformDetection.IsNotBrowser; + + [ConditionalFact(nameof(SupportICUWithUtcAlias))] public static void UtcAliases_MapToUtc() { foreach (string alias in s_UtcAliases)