Tom, Your patch was breaking stuffs, but the reported issue was still valid. Here's the fix and tests I pushed a few minutes ago. it validates against .NET 3.5 too.
regards Stephane On Wed, 2009-12-02 at 14:53 -0800, Tom Philpot wrote: > Stephen, > > Did this patch ever get committed? > > Thanks, > Tom > > > On 11/26/09 5:23 AM, "Stephane Delcroix" <steph...@delcroix.org> > wrote: > > On Wed, 2009-11-25 at 15:04 -0800, Tom Philpot wrote: > > Here's a patch that resolves an issue of adding or > subtracting time from a > > DateTime which crosses the DST boundary. > > Thanks for the patch, I ran into that issue once then forgot > to apply > the patch (that is now lost). Looking at yours and committing. > > > > Again, there don't appear to be test cases for this in the > Mono test suite. > your test case will make an unit test. > > -s > > > > Kudos to Martin Potter on our team for figuring this out. > > > > This patch is licensed under MIT/X11. > > > > > > _______________________________________________ > > Mono-devel-list mailing list > > Mono-devel-list@lists.ximian.com > > http://lists.ximian.com/mailman/listinfo/mono-devel-list > > > >
commit bbc1e860891c2b143eba543bb19bf966ab5c805e Author: stephane <steph...@e3ebcda4-bce8-0310-ba0a-eca2169e7518> Date: Thu Dec 3 11:58:11 2009 +0000 2009-12-03 Stephane Delcroix <steph...@delcroix.org> * DateTimeOffset.cs: fix dates arithmetic to avoid throwing while crossing dst boundaries. git-svn-id: svn+ssh://mono-cvs.ximian.com/source/trunk/m...@147551 e3ebcda4-bce8-0310-ba0a-eca2169e7518 diff --git a/class/corlib/System/ChangeLog b/class/corlib/System/ChangeLog index 5ccb57e..e951718 100644 --- a/class/corlib/System/ChangeLog +++ b/class/corlib/System/ChangeLog @@ -1,3 +1,8 @@ +2009-12-03 Stephane Delcroix <steph...@delcroix.org> + + * DateTimeOffset.cs: fix dates arithmetic to avoid throwing + while crossing dst boundaries. + 2009-12-03 Jb Evain <jbev...@novell.com> * Attribute.cs: remove code duplication. diff --git a/class/corlib/System/DateTimeOffset.cs b/class/corlib/System/DateTimeOffset.cs index c8e544c..ab6ec29 100644 --- a/class/corlib/System/DateTimeOffset.cs +++ b/class/corlib/System/DateTimeOffset.cs @@ -101,17 +101,17 @@ namespace System public DateTimeOffset Add (TimeSpan timeSpan) { - return new DateTimeOffset (dt.Add (timeSpan), utc_offset); + return new DateTimeOffset (dt.Add (timeSpan).Ticks, utc_offset); } public DateTimeOffset AddDays (double days) { - return new DateTimeOffset (dt.AddDays (days), utc_offset); + return new DateTimeOffset (dt.AddDays (days).Ticks, utc_offset); } public DateTimeOffset AddHours (double hours) { - return new DateTimeOffset (dt.AddHours (hours), utc_offset); + return new DateTimeOffset (dt.AddHours (hours).Ticks, utc_offset); } public static DateTimeOffset operator + (DateTimeOffset dateTimeTz, TimeSpan timeSpan) @@ -121,32 +121,32 @@ namespace System public DateTimeOffset AddMilliseconds (double milliseconds) { - return new DateTimeOffset (dt.AddMilliseconds (milliseconds), utc_offset); + return new DateTimeOffset (dt.AddMilliseconds (milliseconds).Ticks, utc_offset); } public DateTimeOffset AddMinutes (double minutes) { - return new DateTimeOffset (dt.AddMinutes (minutes), utc_offset); + return new DateTimeOffset (dt.AddMinutes (minutes).Ticks, utc_offset); } public DateTimeOffset AddMonths (int months) { - return new DateTimeOffset (dt.AddMonths (months), utc_offset); + return new DateTimeOffset (dt.AddMonths (months).Ticks, utc_offset); } public DateTimeOffset AddSeconds (double seconds) { - return new DateTimeOffset (dt.AddSeconds (seconds), utc_offset); + return new DateTimeOffset (dt.AddSeconds (seconds).Ticks, utc_offset); } public DateTimeOffset AddTicks (long ticks) { - return new DateTimeOffset (dt.AddTicks (ticks), utc_offset); + return new DateTimeOffset (dt.AddTicks (ticks).Ticks, utc_offset); } public DateTimeOffset AddYears (int years) { - return new DateTimeOffset (dt.AddYears (years), utc_offset); + return new DateTimeOffset (dt.AddYears (years).Ticks, utc_offset); } public static int Compare (DateTimeOffset first, DateTimeOffset second) diff --git a/class/corlib/Test/System/DateTimeOffsetTest.cs b/class/corlib/Test/System/DateTimeOffsetTest.cs index ec2b91f..24f9aa1 100644 --- a/class/corlib/Test/System/DateTimeOffsetTest.cs +++ b/class/corlib/Test/System/DateTimeOffsetTest.cs @@ -618,7 +618,16 @@ namespace MonoTests.System { } return result; } - + + [Test] + public void ArithmeticAccrossDSTBoudaries () + { + DateTime dt = new DateTime (633954393584177800, DateTimeKind.Local); //Dec 3, 2009, 12:16 + DateTimeOffset dto = new DateTimeOffset (dt); + DateTimeOffset dto2 = dto.AddDays (-60); //Should cross the late Oct boundary in most part of the world + Assert.AreEqual (dto.Offset, dto2.Offset); + Assert.AreEqual (dt.AddDays (-60), dto2.DateTime); + } } } #endif
_______________________________________________ Mono-devel-list mailing list Mono-devel-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-devel-list