Author: stephane
Date: 2007-12-10 11:46:16 -0500 (Mon, 10 Dec 2007)
New Revision: 91050

Modified:
   trunk/mcs/class/corlib/System/ChangeLog
   trunk/mcs/class/corlib/System/DateTimeOffset.cs
Log:
2007-12-10  Stephane Delcroix  <[EMAIL PROTECTED]>

        * DateTimeOffset.cs: partial implementation. no longer just a stub.


Modified: trunk/mcs/class/corlib/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System/ChangeLog     2007-12-10 15:42:21 UTC (rev 
91049)
+++ trunk/mcs/class/corlib/System/ChangeLog     2007-12-10 16:46:16 UTC (rev 
91050)
@@ -1,3 +1,7 @@
+2007-12-10  Stephane Delcroix  <[EMAIL PROTECTED]>
+
+       * DateTimeOffset.cs: partial implementation. no longer just a stub.
+
 2007-11-30  Zoltan Varga  <[EMAIL PROTECTED]>
 
        * Delegate.cs: Compute the Method property lazily.

Modified: trunk/mcs/class/corlib/System/DateTimeOffset.cs
===================================================================
--- trunk/mcs/class/corlib/System/DateTimeOffset.cs     2007-12-10 15:42:21 UTC 
(rev 91049)
+++ trunk/mcs/class/corlib/System/DateTimeOffset.cs     2007-12-10 16:46:16 UTC 
(rev 91050)
@@ -30,34 +30,149 @@
 
 #if NET_2_0 // Introduced by .NET 3.5 for 2.0 mscorlib
 
+using System.Globalization;
 using System.Runtime.InteropServices;
+using System.Runtime.Serialization;
 
 namespace System
 {
        [Serializable]
        [StructLayout (LayoutKind.Auto)]
-       public struct DateTimeOffset
+       public struct DateTimeOffset : IComparable, IFormattable, 
ISerializable, IDeserializationCallback, IComparable<DateTimeOffset>, 
IEquatable<DateTimeOffset>
        {
                public static readonly DateTimeOffset MaxValue = new 
DateTimeOffset (DateTime.MaxValue);
                public static readonly DateTimeOffset MinValue = new 
DateTimeOffset (DateTime.MaxValue);
                
                DateTime dt;
-               
+               TimeSpan utc_offset;
+       
                public DateTimeOffset (DateTime dateTime)
                {
-                       this.dt = dateTime;
+                       dt = dateTime;
+
+                       if (dateTime.Kind == DateTimeKind.Utc)
+                               utc_offset = TimeSpan.Zero;
+                       else 
+                               utc_offset = 
TimeZone.CurrentTimeZone.GetUtcOffset (dateTime);
+                               
+                       if (UtcDateTime < DateTime.MinValue || UtcDateTime > 
DateTime.MaxValue)
+                               throw new ArgumentOutOfRangeException ("The UTC 
date and time that results from applying the offset is earlier than MinValue or 
later than MaxValue.");
+
                }
                
+               public DateTimeOffset (DateTime dateTime, TimeSpan offset)
+               {
+                       if (dateTime.Kind == DateTimeKind.Utc && offset != 
TimeSpan.Zero)
+                               throw new ArgumentException ("dateTime.Kind 
equals Utc and offset does not equal zero.");
+
+                       if (dateTime.Kind == DateTimeKind.Local && offset != 
TimeZone.CurrentTimeZone.GetUtcOffset (dateTime))
+                               throw new ArgumentException ("dateTime.Kind 
equals Local and offset does not equal the offset of the system's local time 
zone.");
+
+                       if (offset.Ticks % TimeSpan.TicksPerMinute != 0)
+                               throw new ArgumentException ("offset is not 
specified in whole minutes.");
+
+                       if (offset < new TimeSpan (-14, 0 ,0) || offset > new 
TimeSpan (14, 0, 0))
+                               throw new ArgumentOutOfRangeException ("offset 
is less than -14 hours or greater than 14 hours.");
+
+                       dt = dateTime;
+                       utc_offset = offset;
+
+                       if (UtcDateTime < DateTime.MinValue || UtcDateTime > 
DateTime.MaxValue)
+                               throw new ArgumentOutOfRangeException ("The 
UtcDateTime property is earlier than MinValue or later than MaxValue.");
+               }
+
+               public DateTimeOffset (long ticks, TimeSpan offset) : this (new 
DateTime (ticks), offset)
+               {
+               }
+
+               public DateTimeOffset (int year, int month, int day, int hour, 
int minute, int second, TimeSpan offset) : 
+                       this (new DateTime (year, month, day, hour, minute, 
second), offset)
+               {
+               }
+
+               public DateTimeOffset (int year, int month, int day, int hour, 
int minute, int second, int millisecond, TimeSpan offset) :
+                       this (new DateTime (year, month, day, hour, minute, 
second, millisecond), offset)
+               {
+               }
+
+               public DateTimeOffset (int year, int month, int day, int hour, 
int minute, int second, int millisecond, Calendar calendar, TimeSpan offset) :
+                       this (new DateTime (year, month, day, hour, minute, 
second, millisecond, calendar), offset)
+               {
+               }
+
                public DateTimeOffset AddSeconds (double seconds)
                {
                        return new DateTimeOffset (this.dt.AddSeconds 
(seconds));
                }
                
+               public int CompareTo (DateTimeOffset other)
+               {
+                       return UtcDateTime.CompareTo (other);
+               }
+
+               public int CompareTo (object other)
+               {
+                       return UtcDateTime.CompareTo (other);
+               }
+
+               public bool Equals (DateTimeOffset other)
+               {
+                       return UtcDateTime == other.UtcDateTime;
+               }
+
+               public override bool Equals (object other)
+               {
+                       return UtcDateTime == ((DateTimeOffset) 
other).UtcDateTime;
+               }
+
+               public static bool Equals (DateTimeOffset first, DateTimeOffset 
second)
+               {
+                       return first.Equals (second);   
+               }
+
+               public override int GetHashCode ()
+               {
+                       return dt.GetHashCode () ^ utc_offset.GetHashCode ();
+               }
+
+               [MonoTODO]
+               public void GetObjectData (SerializationInfo info, 
StreamingContext context)
+               {
+                       throw new NotImplementedException ();   
+               }
+
+               [MonoTODO]
+               public void OnDeserialization (object sender)
+               {
+                       throw new NotImplementedException ();   
+               }
+
+               [MonoTODO]
+               public string ToString (string format, IFormatProvider 
formatProvider)
+               {
+                       throw new NotImplementedException ();   
+               }
+
                public DateTime DateTime {
                        get {
-                               return dt;
+                               if (dt.Kind == DateTimeKind.Unspecified)
+                                       return dt;
+                               else
+                                       return DateTime.SpecifyKind (dt, 
DateTimeKind.Unspecified);
                        }
                }
+
+               public TimeSpan Offset {
+                       get {
+                               return utc_offset;      
+                       }       
+               }
+
+               public DateTime UtcDateTime {
+                       get {
+                               return DateTime.SpecifyKind (dt - utc_offset, 
DateTimeKind.Utc);
+                       }       
+               }
                
                public static DateTimeOffset Now {
                        get {
@@ -67,12 +182,12 @@
                
                public static bool operator < (DateTimeOffset dto1, 
DateTimeOffset dto2)
                {
-                       return dto1.dt < dto2.dt;
+                       return dto1.UtcDateTime < dto2.UtcDateTime;
                }
                
                public static bool operator > (DateTimeOffset dto1, 
DateTimeOffset dto2)
                {
-                       return dto1.dt > dto2.dt;
+                       return dto1.UtcDateTime > dto2.UtcDateTime;
                }                       
        }
 }

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

Reply via email to