From e6f5369c2d24aa2de511a52c8a58956c3283c4e4 Mon Sep 17 00:00:00 2001 From: monojenkins Date: Thu, 27 Jun 2019 13:12:51 -0400 Subject: [PATCH] [2019-02] Fix time zone transition out of DST (#15444) * Time zone DST out fix * Add unit tests for Europe/Vatican, Iran and Europe/Guernsey time zones * Disable the tests on WINAOT; fixed Iran time zone id --- mcs/class/corlib/System/TimeZoneInfo.cs | 6 +++++ .../corlib/Test/System/TimeZoneInfoTest.cs | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/mcs/class/corlib/System/TimeZoneInfo.cs b/mcs/class/corlib/System/TimeZoneInfo.cs index 5f9cba007414a..72ad64ad3ff30 100644 --- a/mcs/class/corlib/System/TimeZoneInfo.cs +++ b/mcs/class/corlib/System/TimeZoneInfo.cs @@ -1236,6 +1236,12 @@ private bool TryGetTransitionOffset (DateTime dateTime, out TimeSpan offset, out isDst = true; } + if (date >= new DateTime (tEnd.Ticks - current.DaylightDelta.Ticks, DateTimeKind.Utc)) + { + offset = baseUtcOffset; + isDst = false; + } + return true; } } diff --git a/mcs/class/corlib/Test/System/TimeZoneInfoTest.cs b/mcs/class/corlib/Test/System/TimeZoneInfoTest.cs index 51159cc8f70f6..9f7340d3d15ec 100644 --- a/mcs/class/corlib/Test/System/TimeZoneInfoTest.cs +++ b/mcs/class/corlib/Test/System/TimeZoneInfoTest.cs @@ -72,6 +72,10 @@ public static string MapTimeZoneId (string id) return "W. Europe Standard Time"; case "Canada/Eastern": return "Eastern Standard Time"; + case "Asia/Tehran": + return "Iran Standard Time"; + case "Europe/Guernsey": + return "GMT Standard Time"; default: Assert.Fail ($"No mapping defined for zone id '{id}'"); return null; @@ -459,6 +463,24 @@ public void Bug_9664 () date = new DateTime (2019, 3, 10, 3, 0, 0); Assert.IsTrue (tzi.IsDaylightSavingTime (date)); Assert.AreEqual (new TimeSpan (-5, 0, 0), tzi.GetUtcOffset (date)); + +#if !WINAOT // https://github.com/mono/mono/issues/15439 + tzi = TimeZoneInfo.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Vatican")); + date = new DateTime (2018, 10, 28, 2, 15, 0); + Assert.IsFalse (tzi.IsDaylightSavingTime (date)); + Assert.AreEqual (new TimeSpan (1, 0, 0), tzi.GetUtcOffset (date)); + + tzi = TimeZoneInfo.FindSystemTimeZoneById (MapTimeZoneId ("Asia/Tehran")); + date = new DateTime (2018, 9, 21, 23, 15, 0); + Assert.IsFalse (tzi.IsDaylightSavingTime (date)); + Assert.AreEqual (new TimeSpan (3, 30, 0), tzi.GetUtcOffset (date)); + + // for Greenwitch Mean Time (Guernsey) + tzi = TimeZoneInfo.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Guernsey")); + date = new DateTime (2019, 10, 27, 1, 15, 0); + Assert.IsFalse (tzi.IsDaylightSavingTime (date)); + Assert.AreEqual (new TimeSpan (0, 0, 0), tzi.GetUtcOffset (date)); +#endif } }