2007-11-14 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mcs / class / corlib / System / TimeSpan.cs
index 2bb950ee9b42f98688ea10e76142afba518c5a22..9ae9da02a9444e0b7cb81e033bc606f478aafafa 100644 (file)
@@ -35,7 +35,13 @@ using System.Text;
 namespace System
 {
        [Serializable]
+#if NET_2_0
+       [System.Runtime.InteropServices.ComVisible (true)]
+#endif
        public struct TimeSpan : IComparable
+#if NET_2_0
+               , IComparable<TimeSpan>, IEquatable <TimeSpan>
+#endif
        {
                public static readonly TimeSpan MaxValue = new TimeSpan (long.MaxValue);
                public static readonly TimeSpan MinValue = new TimeSpan (long.MinValue);
@@ -216,6 +222,18 @@ namespace System
                        return Compare (this, (TimeSpan) value);
                }
 
+#if NET_2_0
+               public int CompareTo (TimeSpan value)
+               {
+                       return Compare (this, value);
+               }
+
+               public bool Equals (TimeSpan value)
+               {
+                       return value._ticks == _ticks;
+               }
+#endif
+
                public TimeSpan Duration ()
                {
                        try {
@@ -316,6 +334,19 @@ namespace System
                        return p.Execute ();
                }
 
+#if NET_2_0
+               public static bool TryParse (string s, out TimeSpan result)
+               {
+                       try {
+                               result = Parse (s);
+                               return true;
+                       } catch {
+                               result = TimeSpan.Zero;
+                               return false;
+                       }
+               }
+#endif
+
                public TimeSpan Subtract (TimeSpan ts)
                {
                        try {
@@ -344,16 +375,17 @@ namespace System
                                sb.Append ('.');
                        }
 
-                       sb.Append (IntegerFormatter.FormatDecimal (Math.Abs (Hours), 2, 4));
+                       System.Globalization.NumberFormatInfo nfi = System.Globalization.CultureInfo.CurrentCulture.NumberFormat;
+                       sb.Append (NumberFormatter.FormatDecimal (new NumberFormatter.NumberStore ((int)Math.Abs (Hours)), 2, nfi));
                        sb.Append (':');
-                       sb.Append (IntegerFormatter.FormatDecimal (Math.Abs (Minutes), 2, 4));
+                       sb.Append (NumberFormatter.FormatDecimal (new NumberFormatter.NumberStore ((int)Math.Abs (Minutes)), 2, nfi));
                        sb.Append (':');
-                       sb.Append (IntegerFormatter.FormatDecimal (Math.Abs (Seconds), 2, 4));
+                       sb.Append (NumberFormatter.FormatDecimal (new NumberFormatter.NumberStore ((int)Math.Abs (Seconds)), 2, nfi));
 
                        int fractional = (int) Math.Abs (_ticks % TicksPerSecond);
                        if (fractional != 0) {
                                sb.Append ('.');
-                               sb.Append (IntegerFormatter.FormatDecimal (Math.Abs (fractional), 7, 4));
+                               sb.Append (NumberFormatter.FormatDecimal (new NumberFormatter.NumberStore (fractional), 7, nfi));
                        }
 
                        return sb.ToString ();