Author: atsushi
Date: 2006-07-07 05:02:59 -0400 (Fri, 07 Jul 2006)
New Revision: 62343

Modified:
   trunk/mcs/class/corlib/System/ChangeLog
   trunk/mcs/class/corlib/System/DateTime.cs
   trunk/mcs/class/corlib/System/TimeZone.cs
   trunk/mcs/class/corlib/Test/System/ChangeLog
   trunk/mcs/class/corlib/Test/System/DateTimeTest.cs
Log:
2006-07-07  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * TimeZone.cs : consider DateTimeKind in ToLocalTime() and 
          ToUniversalTime(). Fixed bug #78784. Patch by Thong Nguyen.
        * DateTime.cs : DateTimeKind for UtcNow should be Utc.

        * DateTimeTest.cs : test for DateTimeKind handling in ToLocalTime()
          and ToUniversalTime() (bug #78784).



Modified: trunk/mcs/class/corlib/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System/ChangeLog     2006-07-07 07:16:05 UTC (rev 
62342)
+++ trunk/mcs/class/corlib/System/ChangeLog     2006-07-07 09:02:59 UTC (rev 
62343)
@@ -1,3 +1,9 @@
+2006-07-07  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * TimeZone.cs : consider DateTimeKind in ToLocalTime() and 
+         ToUniversalTime(). Fixed bug #78784. Patch by Thong Nguyen.
+       * DateTime.cs : DateTimeKind for UtcNow should be Utc.
+
 2006-06-28  Kornél Pál  <[EMAIL PROTECTED]>
 
        * Char.cs: Implemented IsHighSurrogate and IsLowSurrogate methods.

Modified: trunk/mcs/class/corlib/System/DateTime.cs
===================================================================
--- trunk/mcs/class/corlib/System/DateTime.cs   2006-07-07 07:16:05 UTC (rev 
62342)
+++ trunk/mcs/class/corlib/System/DateTime.cs   2006-07-07 09:02:59 UTC (rev 
62343)
@@ -445,7 +445,11 @@
                public static DateTime UtcNow 
                {
                        get {
+#if NET_2_0
+                               return new DateTime (GetNow (), 
DateTimeKind.Utc);
+#else
                                return new DateTime (GetNow ());
+#endif
                        }
                }
 

Modified: trunk/mcs/class/corlib/System/TimeZone.cs
===================================================================
--- trunk/mcs/class/corlib/System/TimeZone.cs   2006-07-07 07:16:05 UTC (rev 
62342)
+++ trunk/mcs/class/corlib/System/TimeZone.cs   2006-07-07 09:02:59 UTC (rev 
62343)
@@ -107,11 +107,20 @@
 
                public virtual DateTime ToLocalTime (DateTime time)
                {
+#if NET_2_0
+                       if (time.Kind == DateTimeKind.Local)
+                               return time;
+#endif
+
                        DaylightTime dlt = GetDaylightChanges (time.Year);
                        TimeSpan utcOffset = GetUtcOffset (time);
                        if (utcOffset.Ticks > 0) {
                                if (DateTime.MaxValue - utcOffset < time)
+#if NET_2_0
+                                       return DateTime.SpecifyKind 
(DateTime.MaxValue, DateTimeKind.Local);
+#else
                                        return DateTime.MaxValue;
+#endif
                        //} else if (utcOffset.Ticks < 0) {
                        //      LAMESPEC: MS.NET fails to check validity here
                        //      it may throw ArgumentOutOfRangeException.
@@ -119,7 +128,11 @@
 
                        DateTime local = time.Add (utcOffset);
                        if (dlt.Delta.Ticks == 0)
+#if NET_2_0
+                               return DateTime.SpecifyKind (local, 
DateTimeKind.Local);
+#else
                                return local;
+#endif
 
                        // FIXME: check all of the combination of
                        //      - basis: local-based or UTC-based
@@ -128,27 +141,56 @@
 
                        // PST should work fine here.
                        if (local < dlt.End && dlt.End.Subtract (dlt.Delta) <= 
local)
+#if NET_2_0
+                               return DateTime.SpecifyKind (local, 
DateTimeKind.Local);
+#else
                                return local;
+#endif
                        if (local >= dlt.Start && dlt.Start.Add (dlt.Delta) > 
local)
+#if NET_2_0
+                               return DateTime.SpecifyKind (local.Subtract 
(dlt.Delta), DateTimeKind.Local);
+#else
                                return local.Subtract (dlt.Delta);
+#endif
 
                        TimeSpan localOffset = GetUtcOffset (local);
+#if NET_2_0
+                       return DateTime.SpecifyKind (time.Add (localOffset), 
DateTimeKind.Local);
+#else
                        return time.Add (localOffset);
+#endif
                }
 
                public virtual DateTime ToUniversalTime (DateTime time)
                {
+#if NET_2_0
+                       if (time.Kind == DateTimeKind.Utc)
+                               return time;
+#endif
+
                        TimeSpan offset = GetUtcOffset (time);
 
                        if (offset.Ticks < 0) {
                                if (DateTime.MaxValue + offset < time)
+#if NET_2_0
+                                       return DateTime.SpecifyKind 
(DateTime.MaxValue, DateTimeKind.Utc);
+#else
                                        return DateTime.MaxValue;
+#endif
                        } else if (offset.Ticks > 0) {
                                if (DateTime.MinValue + offset > time)
+#if NET_2_0
+                                       return DateTime.SpecifyKind 
(DateTime.MinValue, DateTimeKind.Utc);
+#else
                                        return DateTime.MinValue;
+#endif
                        }
 
+#if NET_2_0
+                       return DateTime.SpecifyKind (new DateTime (time.Ticks - 
offset.Ticks), DateTimeKind.Utc);
+#else
                        return new DateTime (time.Ticks - offset.Ticks);
+#endif         
                }
        }
 

Modified: trunk/mcs/class/corlib/Test/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System/ChangeLog        2006-07-07 07:16:05 UTC 
(rev 62342)
+++ trunk/mcs/class/corlib/Test/System/ChangeLog        2006-07-07 09:02:59 UTC 
(rev 62343)
@@ -1,3 +1,8 @@
+2006-07-07  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * DateTimeTest.cs : test for DateTimeKind handling in ToLocalTime()
+         and ToUniversalTime() (bug #78784).
+
 2006-06-27  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * DoubleTest.cs : added test for bug #78546.

Modified: trunk/mcs/class/corlib/Test/System/DateTimeTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System/DateTimeTest.cs  2006-07-07 07:16:05 UTC 
(rev 62342)
+++ trunk/mcs/class/corlib/Test/System/DateTimeTest.cs  2006-07-07 09:02:59 UTC 
(rev 62343)
@@ -1463,6 +1463,33 @@
        {
                ((IConvertible)DateTime.Now).ToType (typeof (ulong), null);
        }
+
+#if NET_2_0
+       [Test]
+       public void Kind ()
+       {
+               if (DateTime.Now == DateTime.UtcNow)
+                       return; // This test does not make sense.
+
+               DateTime utc = DateTime.UtcNow;
+               DateTime now = DateTime.Now;
+               DateTime utctouniv = utc.ToUniversalTime ();
+               DateTime nowtouniv = now.ToUniversalTime ();
+               DateTime utctoloc = utc.ToLocalTime ();
+               DateTime nowtoloc = now.ToLocalTime ();
+
+               AssertEquals ("#1", DateTimeKind.Utc, utc.Kind);
+               AssertEquals ("#2", DateTimeKind.Local, now.Kind);
+               AssertEquals ("#3", DateTimeKind.Utc, utctouniv.Kind);
+               AssertEquals ("#4", DateTimeKind.Utc, nowtouniv.Kind);
+               AssertEquals ("#5", DateTimeKind.Local, utctoloc.Kind);
+               AssertEquals ("#6", DateTimeKind.Local, nowtoloc.Kind);
+               AssertEquals ("#7", utc, utctouniv);
+               AssertEquals ("#8", utc, nowtouniv);
+               AssertEquals ("#9", now, nowtoloc);
+               AssertEquals ("#10", now, utctoloc);
+       }
+#endif
 }
 
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to