Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6f5369

Browse files
monojenkinsmarek-safar
authored andcommitted
[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
1 parent 346da98 commit e6f5369

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
@@ -1236,6 +1236,12 @@ private bool TryGetTransitionOffset (DateTime dateTime, out TimeSpan offset, out
12361236
isDst = true;
12371237
}
12381238

1239+
if (date >= new DateTime (tEnd.Ticks - current.DaylightDelta.Ticks, DateTimeKind.Utc))
1240+
{
1241+
offset = baseUtcOffset;
1242+
isDst = false;
1243+
}
1244+
12391245
return true;
12401246
}
12411247
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public static string MapTimeZoneId (string id)
7272
return "W. Europe Standard Time";
7373
case "Canada/Eastern":
7474
return "Eastern Standard Time";
75+
case "Asia/Tehran":
76+
return "Iran Standard Time";
77+
case "Europe/Guernsey":
78+
return "GMT Standard Time";
7579
default:
7680
Assert.Fail ($"No mapping defined for zone id '{id}'");
7781
return null;
@@ -459,6 +463,24 @@ public void Bug_9664 ()
459463
date = new DateTime (2019, 3, 10, 3, 0, 0);
460464
Assert.IsTrue (tzi.IsDaylightSavingTime (date));
461465
Assert.AreEqual (new TimeSpan (-5, 0, 0), tzi.GetUtcOffset (date));
466+
467+
#if !WINAOT // https://github.com/mono/mono/issues/15439
468+
tzi = TimeZoneInfo.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Vatican"));
469+
date = new DateTime (2018, 10, 28, 2, 15, 0);
470+
Assert.IsFalse (tzi.IsDaylightSavingTime (date));
471+
Assert.AreEqual (new TimeSpan (1, 0, 0), tzi.GetUtcOffset (date));
472+
473+
tzi = TimeZoneInfo.FindSystemTimeZoneById (MapTimeZoneId ("Asia/Tehran"));
474+
date = new DateTime (2018, 9, 21, 23, 15, 0);
475+
Assert.IsFalse (tzi.IsDaylightSavingTime (date));
476+
Assert.AreEqual (new TimeSpan (3, 30, 0), tzi.GetUtcOffset (date));
477+
478+
// for Greenwitch Mean Time (Guernsey)
479+
tzi = TimeZoneInfo.FindSystemTimeZoneById (MapTimeZoneId ("Europe/Guernsey"));
480+
date = new DateTime (2019, 10, 27, 1, 15, 0);
481+
Assert.IsFalse (tzi.IsDaylightSavingTime (date));
482+
Assert.AreEqual (new TimeSpan (0, 0, 0), tzi.GetUtcOffset (date));
483+
#endif
462484
}
463485
}
464486

0 commit comments

Comments
 (0)