Skip to content

Commit

Permalink
[2019-02] Fix time zone transition out of DST (#15444)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
monojenkins authored and marek-safar committed Jun 27, 2019
1 parent 346da98 commit e6f5369
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mcs/class/corlib/System/TimeZoneInfo.cs
Expand Up @@ -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;
}
}
Expand Down
22 changes: 22 additions & 0 deletions mcs/class/corlib/Test/System/TimeZoneInfoTest.cs
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit e6f5369

Please sign in to comment.