Skip to content

Commit 329442f

Browse files
MaximLipninscott-ferguson-unity
authored andcommitted
Fix time zone transition out of DST (mono#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 mono#9664.
1 parent 5a85300 commit 329442f

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

mcs/class/corlib/System/TimeZoneInfo.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,12 @@ private bool TryGetTransitionOffset (DateTime dateTime, out TimeSpan offset, out
12721272
isDst = true;
12731273
}
12741274

1275+
if (date >= new DateTime (tEnd.Ticks - current.DaylightDelta.Ticks, DateTimeKind.Utc))
1276+
{
1277+
offset = baseUtcOffset;
1278+
isDst = false;
1279+
}
1280+
12751281
return true;
12761282
}
12771283
}

mcs/class/corlib/Test/System/TimeZoneInfoTest.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public static string MapTimeZoneId (string id)
7171
return "W. Europe Standard Time";
7272
case "Canada/Eastern":
7373
return "Eastern Standard Time";
74+
case "Asia/Tehran":
75+
return "Iran Standard Time";
76+
case "Europe/Guernsey":
77+
return "GMT Standard Time";
7478
default:
7579
Assert.Fail ($"No mapping defined for zone id '{id}'");
7680
return null;
@@ -873,6 +877,24 @@ public void Bug_9664 ()
873877
date = new DateTime (2019, 3, 10, 3, 0, 0);
874878
Assert.IsTrue (tzi.IsDaylightSavingTime (date));
875879
Assert.AreEqual (new TimeSpan (-5, 0, 0), tzi.GetUtcOffset (date));
880+
881+
#if !WINAOT // https://github.com/mono/mono/issues/15439
882+
tzi = TimeZoneInfo.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Vatican"));
883+
date = new DateTime (2018, 10, 28, 2, 15, 0);
884+
Assert.IsFalse (tzi.IsDaylightSavingTime (date));
885+
Assert.AreEqual (new TimeSpan (1, 0, 0), tzi.GetUtcOffset (date));
886+
887+
tzi = TimeZoneInfo.FindSystemTimeZoneById (MapTimeZoneId ("Asia/Tehran"));
888+
date = new DateTime (2018, 9, 21, 23, 15, 0);
889+
Assert.IsFalse (tzi.IsDaylightSavingTime (date));
890+
Assert.AreEqual (new TimeSpan (3, 30, 0), tzi.GetUtcOffset (date));
891+
892+
// for Greenwitch Mean Time (Guernsey)
893+
tzi = TimeZoneInfo.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Guernsey"));
894+
date = new DateTime (2019, 10, 27, 1, 15, 0);
895+
Assert.IsFalse (tzi.IsDaylightSavingTime (date));
896+
Assert.AreEqual (new TimeSpan (0, 0, 0), tzi.GetUtcOffset (date));
897+
#endif
876898
}
877899
}
878900

0 commit comments

Comments
 (0)