From a4b1fa50235c9f213fdaa0e5ad8d26580af4188a Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Fri, 11 Jun 2004 12:43:42 +0000 Subject: 2004-06-11 Sebastien Pouliot * DateTime.cs: Added a AddRoundedMilliseconds which use the "old Mono" rounding logic which worked for FromOADate (while the newer didn't). svn path=/trunk/mcs/; revision=29341 --- mcs/class/corlib/System/ChangeLog | 5 +++++ mcs/class/corlib/System/DateTime.cs | 25 +++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/mcs/class/corlib/System/ChangeLog b/mcs/class/corlib/System/ChangeLog index e55ab3bba9a..c4c08bc9c81 100644 --- a/mcs/class/corlib/System/ChangeLog +++ b/mcs/class/corlib/System/ChangeLog @@ -1,3 +1,8 @@ +2004-06-11 Sebastien Pouliot + + * DateTime.cs: Added a AddRoundedMilliseconds which use the "old Mono" + rounding logic which worked for FromOADate (while the newer didn't). + 2004-06-11 Martin Baulig * String.cs (Concat): Implemented the varargs version. diff --git a/mcs/class/corlib/System/DateTime.cs b/mcs/class/corlib/System/DateTime.cs index 2c1a193fed7..af483154ee0 100644 --- a/mcs/class/corlib/System/DateTime.cs +++ b/mcs/class/corlib/System/DateTime.cs @@ -431,6 +431,18 @@ namespace System return AddTicks (msticks); } + + // required to match MS implementation for OADate (OLE Automation) + private DateTime AddRoundedMilliseconds (double ms) + { + if ((ms * TimeSpan.TicksPerMillisecond) > long.MaxValue || + (ms * TimeSpan.TicksPerMillisecond) < long.MinValue) { + throw new ArgumentOutOfRangeException (); + } + long msticks = (long) (ms += ms > 0 ? 0.5 : -0.5) * TimeSpan.TicksPerMillisecond; + + return AddTicks (msticks); + } public DateTime AddMinutes (double minutes) { @@ -551,17 +563,18 @@ namespace System if (d < 0.0d) { Double days = Math.Ceiling (d); // integer part is the number of days (negative) - dt = dt.AddDays (days); + dt = dt.AddRoundedMilliseconds (days * 86400000); // but decimals are the number of hours (in days fractions) and positive Double hours = (days - d); - dt = dt.AddDays (hours); + dt = dt.AddRoundedMilliseconds (hours * 86400000); + } + else { + dt = dt.AddRoundedMilliseconds (d * 86400000); } - else - dt = dt.AddDays (d); return dt; - } - + } + public string[] GetDateTimeFormats() { return GetDateTimeFormats (CultureInfo.CurrentCulture); -- cgit v1.2.3