From a3be3e1c003b9b9fe9ea6cd09fce281eb10a1e2c Mon Sep 17 00:00:00 2001 From: Michael Render Date: Mon, 10 Jul 2023 21:29:38 -0400 Subject: [PATCH 1/9] [libs][Unix] Fix UTC alias lookup * Fix UTC -> UCT typo * Re-order lookup to match source in the comment linked abovce --- .../System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs index 992035b92df60..2524b4fd53606 100644 --- a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs @@ -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 From b00b0df5d8028a6e4244ad93ef5b740435d5bfe4 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Tue, 11 Jul 2023 17:12:29 -0400 Subject: [PATCH 2/9] Add regression test (non-windows) --- .../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 18c033afd2ade..aec390715d534 100644 --- a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs +++ b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs @@ -2424,6 +2424,16 @@ public static void TimeZoneDisplayNames_Unix(TimeZoneInfo timeZone) } } + [Fact] + [PlatformSpecific(~TestPlatforms.Windows)] + public static void UtcAliases_MapToUtc() + { + foreach (string utcAlias in s_UtcAliases) + { + Assert.Equal(TimeZoneInfo.Utc, TimeZoneInfo.FindSystemTimeZoneById(utcAlias)); + } + } + [ActiveIssue("https://github.com/dotnet/runtime/issues/19794", TestPlatforms.AnyUnix)] [Theory] [MemberData(nameof(SystemTimeZonesTestData))] From 8c9c927720dc24460ec1607467cfd119f454a289 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Tue, 11 Jul 2023 19:14:11 -0400 Subject: [PATCH 3/9] Fix TimeZoneInfo equality. Compare everything except tests. --- .../System.Runtime/tests/System/TimeZoneInfoTests.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs index aec390715d534..2c86e97b0eb4e 100644 --- a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs +++ b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs @@ -2428,9 +2428,14 @@ public static void TimeZoneDisplayNames_Unix(TimeZoneInfo timeZone) [PlatformSpecific(~TestPlatforms.Windows)] public static void UtcAliases_MapToUtc() { + TimeZoneInfo.AdjustmentRule[] expectedAdjustmentRules = TimeZoneInfo.Utc.GetAdjustmentRules(); + foreach (string utcAlias in s_UtcAliases) { - Assert.Equal(TimeZoneInfo.Utc, TimeZoneInfo.FindSystemTimeZoneById(utcAlias)); + TimeZoneInfo actualUtc = TimeZoneInfo.FindSystemTimeZoneById(utcAlias); + Assert.Equal(TimeZoneInfo.Utc.BaseUtcOffset, actualUtc.BaseUtcOffset); + Assert.Equal(TimeZoneInfo.Utc.SupportsDaylightSavingTime, actualUtc.SupportsDaylightSavingTime); + Assert.Equal(expectedAdjustmentRules, actualUtc.GetAdjustmentRules()); } } From 3f21ef50688e6be56bac96ea861ff51a5f25e9a1 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Tue, 11 Jul 2023 19:30:30 -0400 Subject: [PATCH 4/9] Use cleaner TimeZoneInfo.HasSameRules() method --- .../System.Runtime/tests/System/TimeZoneInfoTests.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs index 2c86e97b0eb4e..d9c1ece239a1c 100644 --- a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs +++ b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs @@ -2428,14 +2428,10 @@ public static void TimeZoneDisplayNames_Unix(TimeZoneInfo timeZone) [PlatformSpecific(~TestPlatforms.Windows)] public static void UtcAliases_MapToUtc() { - TimeZoneInfo.AdjustmentRule[] expectedAdjustmentRules = TimeZoneInfo.Utc.GetAdjustmentRules(); - foreach (string utcAlias in s_UtcAliases) { TimeZoneInfo actualUtc = TimeZoneInfo.FindSystemTimeZoneById(utcAlias); - Assert.Equal(TimeZoneInfo.Utc.BaseUtcOffset, actualUtc.BaseUtcOffset); - Assert.Equal(TimeZoneInfo.Utc.SupportsDaylightSavingTime, actualUtc.SupportsDaylightSavingTime); - Assert.Equal(expectedAdjustmentRules, actualUtc.GetAdjustmentRules()); + Assert.True(TimeZoneInfo.Utc.HasSameRules(actualUtc)); } } From 10913360c475a57c77906cf5b1fcd46b1bc7e308 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Tue, 11 Jul 2023 21:42:20 -0400 Subject: [PATCH 5/9] Check only BaseUtcOffset and GetAdjustmentRules() --- .../System.Runtime/tests/System/TimeZoneInfoTests.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs index d9c1ece239a1c..43abf35f1d59f 100644 --- a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs +++ b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs @@ -2428,10 +2428,13 @@ public static void TimeZoneDisplayNames_Unix(TimeZoneInfo timeZone) [PlatformSpecific(~TestPlatforms.Windows)] public static void UtcAliases_MapToUtc() { - foreach (string utcAlias in s_UtcAliases) + TimeZoneInfo.AdjustmentRule[] expectedAdjustmentRules = TimeZoneInfo.Utc.GetAdjustmentRules(); + + foreach (var alias in s_UtcAliases) { - TimeZoneInfo actualUtc = TimeZoneInfo.FindSystemTimeZoneById(utcAlias); - Assert.True(TimeZoneInfo.Utc.HasSameRules(actualUtc)); + TimeZoneInfo actualUtc = TimeZoneInfo.FindSystemTimeZoneById(alias); + Assert.Equal(TimeZoneInfo.Utc.BaseUtcOffset, actualUtc.BaseUtcOffset); + Assert.Equal(expectedAdjustmentRules, actualUtc.GetAdjustmentRules()); } } From ad365f3f2d9319b1eda780c37879f8bf875aeccc Mon Sep 17 00:00:00 2001 From: Michael Render Date: Wed, 12 Jul 2023 01:52:42 -0400 Subject: [PATCH 6/9] Turn off build on browser --- 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 43abf35f1d59f..7c632624ca014 100644 --- a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs +++ b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs @@ -2425,7 +2425,7 @@ public static void TimeZoneDisplayNames_Unix(TimeZoneInfo timeZone) } [Fact] - [PlatformSpecific(~TestPlatforms.Windows)] + [PlatformSpecific(~TestPlatforms.Windows & ~TestPlatforms.Browser)] public static void UtcAliases_MapToUtc() { TimeZoneInfo.AdjustmentRule[] expectedAdjustmentRules = TimeZoneInfo.Utc.GetAdjustmentRules(); From 58ddb053d26f6f81eba469a7e1ed9267c09f1f79 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Wed, 12 Jul 2023 12:59:18 -0400 Subject: [PATCH 7/9] Add UTC aliases to SystemTimeZonesTestData Remove previous test which doesn't hit relevant functinality --- .../tests/System/TimeZoneInfoTests.cs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs index 7c632624ca014..692934427f836 100644 --- a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs +++ b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs @@ -2334,6 +2334,11 @@ public static IEnumerable SystemTimeZonesTestData() yield return new object[] { tz }; } } + + foreach (string alias in s_UtcAliases) + { + yield return new object[] { TimeZoneInfo.FindSystemTimeZoneById(alias) }; + } } } @@ -2424,20 +2429,6 @@ 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))] From 4e122bdf3bd3868e68a154b5aa6e5ab9727679b2 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Wed, 12 Jul 2023 13:25:21 -0400 Subject: [PATCH 8/9] Add back `UtcAliases_MapToUtc` test --- .../tests/System/TimeZoneInfoTests.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs index 692934427f836..f319302e39665 100644 --- a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs +++ b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs @@ -2429,6 +2429,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))] From 5d547ea556e277352cf5a176b520c267eb1cc2b3 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Wed, 12 Jul 2023 23:40:35 -0400 Subject: [PATCH 9/9] don't run UTC alias test on browser --- .../System.Runtime/tests/System/TimeZoneInfoTests.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs index f319302e39665..386ca83b3771f 100644 --- a/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs +++ b/src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs @@ -2335,9 +2335,12 @@ public static IEnumerable SystemTimeZonesTestData() } } - foreach (string alias in s_UtcAliases) + if (!PlatformDetection.IsBrowser) { - yield return new object[] { TimeZoneInfo.FindSystemTimeZoneById(alias) }; + foreach (string alias in s_UtcAliases) + { + yield return new object[] { TimeZoneInfo.FindSystemTimeZoneById(alias) }; + } } } }