提交 bd8909c1 编写于 作者: M Maxim Lipnin 提交者: cprasad-rythmos

Fix time zone transition out of DST (#15401)

When a datetime appears in range of [end_of_DST_period - Daylight_delta; end_of_DST_period] it's not DST and should return base offset.

Fixes #9664.
上级 dc7a88eb
......@@ -1272,6 +1272,12 @@ namespace System
isDst = true;
}
if (date >= new DateTime (tEnd.Ticks - current.DaylightDelta.Ticks, DateTimeKind.Utc))
{
offset = baseUtcOffset;
isDst = false;
}
return true;
}
}
......
......@@ -71,6 +71,10 @@ namespace MonoTests.System
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;
......@@ -873,6 +877,24 @@ namespace MonoTests.System
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
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册