New test.
[mono.git] / mcs / class / corlib / Test / System / TimeSpanTest.cs
1 //
2 // TimeSpanTest.cs - NUnit Test Cases for the System.TimeSpan struct
3 //
4 // Authors:
5 //      Duco Fijma (duco@lorentz.xs4all.nl)
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // (C) 2001 Duco Fijma
9 // Copyright (C) 2004 Novell (http://www.novell.com)
10 //
11
12 using NUnit.Framework;
13 using System;
14 using System.Globalization;
15 using System.Threading;
16
17 namespace MonoTests.System
18 {
19
20 [TestFixture]
21 public class TimeSpanTest {
22
23         private void Debug (TimeSpan ts) 
24         {
25                 Console.Out.WriteLine ("Days {0}", ts.Days);
26                 Console.Out.WriteLine ("Hours {0}", ts.Hours);
27                 Console.Out.WriteLine ("Minutes {0}", ts.Minutes);
28                 Console.Out.WriteLine ("Seconds {0}", ts.Seconds);
29                 Console.Out.WriteLine ("Milliseconds {0}", ts.Milliseconds);
30                 Console.Out.WriteLine ("Ticks {0}", ts.Ticks);
31         }
32
33         public void TestCtors ()
34         {
35                 TimeSpan t1 = new TimeSpan (1234567890);
36
37                 Assert.AreEqual ("00:02:03.4567890", t1.ToString (), "A1");
38                 t1 = new TimeSpan (1,2,3);
39                 Assert.AreEqual ("01:02:03", t1.ToString (), "A2");
40                 t1 = new TimeSpan (1,2,3,4);
41                 Assert.AreEqual ("1.02:03:04", t1.ToString (), "A3");
42                 t1 = new TimeSpan (1,2,3,4,5);
43                 Assert.AreEqual ("1.02:03:04.0050000", t1.ToString (), "A4");
44                 t1 = new TimeSpan (-1,2,-3,4,-5);
45                 Assert.AreEqual ("-22:02:56.0050000", t1.ToString (), "A5");
46                 t1 = new TimeSpan (0,25,0,0,0);
47                 Assert.AreEqual ("1.01:00:00", t1.ToString (), "A6");
48         }
49
50         [Test]
51         [ExpectedException (typeof (ArgumentOutOfRangeException))]
52         public void DaysOverflow () 
53         {
54                 int days = (int) (Int64.MaxValue / TimeSpan.TicksPerDay) + 1;
55                 TimeSpan ts = new TimeSpan (days, 0, 0, 0, 0);
56         }
57
58         [Test]
59 #if NET_2_0
60         [ExpectedException (typeof (ArgumentOutOfRangeException))]
61         [Category ("NotWorking")]
62 #endif
63         public void TemporaryOverflow () 
64         {
65                 // calculating part of this results in overflow (days)
66                 // but the negative hours, minutes, seconds & ms correct this
67                 int days = (int) (Int64.MaxValue / TimeSpan.TicksPerDay) + 1;
68                 TimeSpan ts = new TimeSpan (days, Int32.MinValue, Int32.MinValue, Int32.MinValue, Int32.MinValue);
69                 Assert.AreEqual (10650320, ts.Days, "Days");
70                 Assert.AreEqual (0, ts.Hours, "Hours");
71                 Assert.AreEqual (14, ts.Minutes, "Minutes");
72                 Assert.AreEqual (28, ts.Seconds, "Seconds");
73                 Assert.AreEqual (352, ts.Milliseconds, "Milliseconds");
74                 Assert.AreEqual (9201876488683520000, ts.Ticks, "Ticks");
75         }
76
77         [Test]
78 #if NET_2_0
79         [ExpectedException (typeof (ArgumentOutOfRangeException))]
80         [Category ("NotWorking")]
81 #endif
82         public void NoOverflowInHoursMinsSecondsMS () 
83         {
84                 TimeSpan ts = new TimeSpan (0, Int32.MaxValue, Int32.MaxValue, Int32.MaxValue, Int32.MaxValue);
85                 Assert.AreEqual (24879, ts.Days, "Days");
86                 Assert.AreEqual (22, ts.Hours, "Hours");
87                 Assert.AreEqual (44, ts.Minutes, "Minutes");
88                 Assert.AreEqual (30, ts.Seconds, "Seconds");
89                 Assert.AreEqual (647, ts.Milliseconds, "Milliseconds");
90                 Assert.AreEqual (21496274706470000, ts.Ticks, "Ticks");
91         }
92
93         [Test]
94         [ExpectedException (typeof (ArgumentOutOfRangeException))]
95         public void MaxDays () 
96         {
97                 new TimeSpan (Int32.MaxValue, 0, 0, 0, 0);
98         }
99
100         [Test]
101         [ExpectedException (typeof (ArgumentOutOfRangeException))]
102         public void MinDays () 
103         {
104                 new TimeSpan (Int32.MinValue, 0, 0, 0, 0);
105         }
106
107         [Test]
108         [Ignore ("too long")]
109         public void MaxHours_TooLong () 
110         {
111                 // LAMESPEC: the highest hours are "special"
112                 for (int i=0; i < 596523; i++) {
113                         TimeSpan ts = new TimeSpan (0, Int32.MaxValue - i, 0, 0, 0);
114                         int h = i + 1;
115                         string prefix = i.ToString () + '-';
116                         Assert.AreEqual (-(h / 24), ts.Days, prefix + "Days");
117                         Assert.AreEqual (-(h % 24), ts.Hours, prefix + "Hours");
118                         Assert.AreEqual (0, ts.Minutes, prefix + "Minutes");
119                         Assert.AreEqual (0, ts.Seconds, prefix + "Seconds");
120                         Assert.AreEqual (0, ts.Milliseconds, prefix + "Milliseconds");
121                         Assert.AreEqual (-36000000000 * h, ts.Ticks, prefix + "Ticks");
122                 }
123         }
124
125         [Test]
126 #if NET_2_0
127         [ExpectedException (typeof (ArgumentOutOfRangeException))]
128         [Category ("NotWorking")]
129 #endif
130         public void MaxHours () 
131         {
132                 // LAMESPEC: the highest hours are "special"
133                 TimeSpan ts = new TimeSpan (0, Int32.MaxValue, 0, 0, 0);
134                 Assert.AreEqual (0, ts.Days, "Max-Days");
135                 Assert.AreEqual (-1, ts.Hours, "Max-Hours");
136                 Assert.AreEqual (0, ts.Minutes, "Max-Minutes");
137                 Assert.AreEqual (0, ts.Seconds, "Max-Seconds");
138                 Assert.AreEqual (0, ts.Milliseconds, "Max-Milliseconds");
139                 Assert.AreEqual (-36000000000, ts.Ticks, "Max-Ticks");
140
141                 ts = new TimeSpan (0, Int32.MaxValue - 596522, 0, 0, 0);
142                 Assert.AreEqual (-24855, ts.Days, "Days");
143                 Assert.AreEqual (-3, ts.Hours, "Hours");
144                 Assert.AreEqual (0, ts.Minutes, "Minutes");
145                 Assert.AreEqual (0, ts.Seconds, "Seconds");
146                 Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
147                 Assert.AreEqual (-21474828000000000, ts.Ticks, "Ticks");
148         }
149
150         [Test]
151 #if NET_2_0
152         [ExpectedException (typeof (ArgumentOutOfRangeException))]
153         [Category ("NotWorking")]
154 #endif
155         public void MaxHours_BreakPoint () 
156         {
157                 TimeSpan ts = new TimeSpan (0, Int32.MaxValue - 596523, 0, 0, 0);
158                 Assert.AreEqual (24855, ts.Days, "Days");
159                 Assert.AreEqual (2, ts.Hours, "Hours");
160                 Assert.AreEqual (28, ts.Minutes, "Minutes");
161                 Assert.AreEqual (16, ts.Seconds, "Seconds");
162                 Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
163                 Assert.AreEqual (21474808960000000, ts.Ticks, "Ticks");
164         }
165
166         [Test]
167         [Ignore ("too long")]
168         public void MinHours_TooLong () 
169         {
170                 // LAMESPEC: the lowest hours are "special"
171                 for (int i=Int32.MinValue; i < -2146887124; i++) {
172                         TimeSpan ts = new TimeSpan (0, i, 0, 0, 0);
173                         int h = i + Int32.MaxValue + 1;
174                         string prefix = i.ToString () + '-';
175                         Assert.AreEqual ((h / 24), ts.Days, prefix + "Days");
176                         Assert.AreEqual ((h % 24), ts.Hours, prefix + "Hours");
177                         Assert.AreEqual (0, ts.Minutes, prefix + "Minutes");
178                         Assert.AreEqual (0, ts.Seconds, prefix + "Seconds");
179                         Assert.AreEqual (0, ts.Milliseconds, prefix + "Milliseconds");
180                         Assert.AreEqual (36000000000 * h, ts.Ticks, prefix + "Ticks");
181                 }
182         }
183
184         [Test]
185 #if NET_2_0
186         [Category ("NotWorking")]
187 #endif
188         public void MinHours () 
189         {
190 #if NET_2_0
191                 TimeSpan ts = new TimeSpan (0, -256204778, 0, 0, 0);
192                 Assert.AreEqual (-10675199, ts.Days, "Days");
193                 Assert.AreEqual (-2, ts.Hours, "Hours");
194                 Assert.AreEqual (0, ts.Minutes, "Minutes");
195                 Assert.AreEqual (0, ts.Seconds, "Seconds");
196                 Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
197                 Assert.AreEqual (-9223372008000000000, ts.Ticks, "Ticks");
198 #else
199                 // LAMESPEC: the lowest hours are "special"
200                 TimeSpan ts = new TimeSpan (0, Int32.MinValue, 0, 0, 0);
201                 Assert.AreEqual (0, ts.Days, "Min-Days");
202                 Assert.AreEqual (0, ts.Hours, "Min-Hours");
203                 Assert.AreEqual (0, ts.Minutes, "Min-Minutes");
204                 Assert.AreEqual (0, ts.Seconds, "Min-Seconds");
205                 Assert.AreEqual (0, ts.Milliseconds, "Min-Milliseconds");
206                 Assert.AreEqual (0, ts.Ticks, "Min-Ticks");
207
208                 ts = new TimeSpan (0, -2146887125, 0, 0, 0);
209                 Assert.AreEqual (24855, ts.Days, "Days");
210                 Assert.AreEqual (3, ts.Hours, "Hours");
211                 Assert.AreEqual (0, ts.Minutes, "Minutes");
212                 Assert.AreEqual (0, ts.Seconds, "Seconds");
213                 Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
214                 Assert.AreEqual (21474828000000000, ts.Ticks, "Ticks");
215 #endif
216         }
217
218         [Test]
219 #if NET_2_0
220         [ExpectedException (typeof (ArgumentOutOfRangeException))]
221         [Category ("NotWorking")]
222 #endif
223         public void MinHours_BreakPoint () 
224         {
225                 TimeSpan ts = new TimeSpan (0, -2146887124, 0, 0, 0);
226                 Assert.AreEqual (-24855, ts.Days, "Days");
227                 Assert.AreEqual (-2, ts.Hours, "Hours");
228                 Assert.AreEqual (-28, ts.Minutes, "Minutes");
229                 Assert.AreEqual (-16, ts.Seconds, "Seconds");
230                 Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
231                 Assert.AreEqual (-21474808960000000, ts.Ticks, "Ticks");
232         }
233
234         [Test]
235         [Ignore ("too long")]
236         public void MaxMinutes_TooLong () 
237         {
238                 // LAMESPEC: the highest minutes are "special"
239                 for (int i=0; i < 35791394; i++) {
240                         TimeSpan ts = new TimeSpan (0, 0, Int32.MaxValue - i, 0, 0);
241                         long h = -(i + 1);
242                         string prefix = i.ToString () + '-';
243                         Assert.AreEqual ((h / 1440), ts.Days, prefix + "Days");
244                         Assert.AreEqual (((h / 60) % 24), ts.Hours, prefix + "Hours");
245                         Assert.AreEqual ((h % 60), ts.Minutes, prefix + "Minutes");
246                         Assert.AreEqual (0, ts.Seconds, prefix + "Seconds");
247                         Assert.AreEqual (0, ts.Milliseconds, prefix + "Milliseconds");
248                         Assert.AreEqual ((600000000L * h), ts.Ticks, prefix + "Ticks");
249                 }
250         }
251
252         [Test]
253 #if NET_2_0
254         [Category ("NotWorking")]
255 #endif
256         public void MaxMinutes () 
257         {
258                 TimeSpan ts;
259 #if NET_2_0
260                 ts = new TimeSpan (0, 0, 256204778, 0, 0);
261                 Assert.AreEqual (177919, ts.Days, "Max-Days");
262                 Assert.AreEqual (23, ts.Hours, "Max-Hours");
263                 Assert.AreEqual (38, ts.Minutes, "Max-Minutes");
264                 Assert.AreEqual (0, ts.Seconds, "Max-Seconds");
265                 Assert.AreEqual (0, ts.Milliseconds, "Max-Milliseconds");
266                 Assert.AreEqual (153722866800000000, ts.Ticks, "Max-Ticks");
267 #else
268                 // LAMESPEC: the highest minutes are "special"
269                 ts = new TimeSpan (0, 0, Int32.MaxValue, 0, 0);
270                 Assert.AreEqual (0, ts.Days, "Max-Days");
271                 Assert.AreEqual (0, ts.Hours, "Max-Hours");
272                 Assert.AreEqual (-1, ts.Minutes, "Max-Minutes");
273                 Assert.AreEqual (0, ts.Seconds, "Max-Seconds");
274                 Assert.AreEqual (0, ts.Milliseconds, "Max-Milliseconds");
275                 Assert.AreEqual (-600000000, ts.Ticks, "Max-Ticks");
276
277                 ts = new TimeSpan (0, 0, Int32.MaxValue - 35791393, 0, 0);
278                 Assert.AreEqual (-24855, ts.Days, "Days");
279                 Assert.AreEqual (-3, ts.Hours, "Hours");
280                 Assert.AreEqual (-14, ts.Minutes, "Minutes");
281                 Assert.AreEqual (0, ts.Seconds, "Seconds");
282                 Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
283                 Assert.AreEqual (-21474836400000000, ts.Ticks, "Ticks");
284 #endif
285         }
286
287         [Test]
288 #if NET_2_0
289         [ExpectedException (typeof (ArgumentOutOfRangeException))]
290         [Category ("NotWorking")]
291 #endif
292         public void MaxMinutes_BreakPoint () 
293         {
294                 TimeSpan ts = new TimeSpan (0, Int32.MaxValue - 35791394, 0, 0, 0);
295                 Assert.AreEqual (0, ts.Days, "Days");
296                 Assert.AreEqual (0, ts.Hours, "Hours");
297                 Assert.AreEqual (-52, ts.Minutes, "Minutes");
298                 Assert.AreEqual (0, ts.Seconds, "Seconds");
299                 Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
300                 Assert.AreEqual (-31200000000, ts.Ticks, "Ticks");
301         }
302
303         [Test]
304         [Ignore ("too long")]
305         public void MinMinutes_TooLong () 
306         {
307                 // LAMESPEC: the highest minutes are "special"
308                 for (int i=Int32.MinValue; i < -2111692253; i++) {
309                         TimeSpan ts = new TimeSpan (0, 0, i, 0, 0);
310                         long h = i + Int32.MaxValue + 1;
311                         string prefix = i.ToString () + '-';
312                         Assert.AreEqual ((h / 1440), ts.Days, prefix + "Days");
313                         Assert.AreEqual (((h / 60) % 24), ts.Hours, prefix + "Hours");
314                         Assert.AreEqual ((h % 60), ts.Minutes, prefix + "Minutes");
315                         Assert.AreEqual (0, ts.Seconds, prefix + "Seconds");
316                         Assert.AreEqual (0, ts.Milliseconds, prefix + "Milliseconds");
317                         Assert.AreEqual ((600000000L * h), ts.Ticks, prefix + "Ticks");
318                 }
319         }
320
321         [Test]
322 #if NET_2_0
323         [Category ("NotWorking")]
324 #endif
325         public void MinMinutes () 
326         {
327                 TimeSpan ts;
328 #if NET_2_0
329                 ts = new TimeSpan (0, 0, Int32.MinValue, 0, 0);
330                 Assert.AreEqual (-1491308, ts.Days, "Days");
331                 Assert.AreEqual (-2, ts.Hours, "Hours");
332                 Assert.AreEqual (-8, ts.Minutes, "Minutes");
333                 Assert.AreEqual (0, ts.Seconds, "Seconds");
334                 Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
335                 Assert.AreEqual (-1288490188800000000, ts.Ticks, "Ticks");
336 #else
337                 // LAMESPEC: the highest minutes are "special"
338                 ts = new TimeSpan (0, 0, Int32.MinValue, 0, 0);
339                 Assert.AreEqual (0, ts.Days, "Min-Days");
340                 Assert.AreEqual (0, ts.Hours, "Min-Hours");
341                 Assert.AreEqual (0, ts.Minutes, "Min-Minutes");
342                 Assert.AreEqual (0, ts.Seconds, "Min-Seconds");
343                 Assert.AreEqual (0, ts.Milliseconds, "Min-Milliseconds");
344                 Assert.AreEqual (0, ts.Ticks, "Min-Ticks");
345
346                 ts = new TimeSpan (0, 0, -2111692254, 0, 0);
347                 Assert.AreEqual (24855, ts.Days, "Days");
348                 Assert.AreEqual (3, ts.Hours, "Hours");
349                 Assert.AreEqual (14, ts.Minutes, "Minutes");
350                 Assert.AreEqual (0, ts.Seconds, "Seconds");
351                 Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
352                 Assert.AreEqual (21474836400000000, ts.Ticks, "Ticks");
353 #endif
354         }
355
356         [Test]
357 #if NET_2_0
358         [Category ("NotWorking")]
359 #endif
360         public void MinMinutes_BreakPoint () 
361         {
362 #if NET_2_0
363                 TimeSpan ts = new TimeSpan (0, 0, -2111692253, 0, 0);
364                 Assert.AreEqual (-1466452, ts.Days, "Days");
365                 Assert.AreEqual (-22, ts.Hours, "Hours");
366                 Assert.AreEqual (-53, ts.Minutes, "Minutes");
367                 Assert.AreEqual (-0, ts.Seconds, "Seconds");
368                 Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
369                 Assert.AreEqual (-1267015351800000000, ts.Ticks, "Ticks");
370 #else
371                 TimeSpan ts = new TimeSpan (0, 0, -2111692253, 0, 0);
372                 Assert.AreEqual (-24855, ts.Days, "Days");
373                 Assert.AreEqual (-3, ts.Hours, "Hours");
374                 Assert.AreEqual (-13, ts.Minutes, "Minutes");
375                 Assert.AreEqual (-16, ts.Seconds, "Seconds");
376                 Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
377                 Assert.AreEqual (-21474835960000000, ts.Ticks, "Ticks");
378 #endif
379         }
380
381         [Test]
382         public void MaxSeconds () 
383         {
384                 TimeSpan ts = new TimeSpan (0, 0, 0, Int32.MaxValue, 0);
385                 Assert.AreEqual (24855, ts.Days, "Days");
386                 Assert.AreEqual (3, ts.Hours, "Hours");
387                 Assert.AreEqual (14, ts.Minutes, "Minutes");
388                 Assert.AreEqual (7, ts.Seconds, "Seconds");
389                 Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
390                 Assert.AreEqual (21474836470000000, ts.Ticks, "Ticks");
391         }
392
393         [Test]
394         public void MinSeconds () 
395         {
396                 TimeSpan ts = new TimeSpan (0, 0, 0, Int32.MinValue, 0);
397                 Assert.AreEqual (-24855, ts.Days, "Days");
398                 Assert.AreEqual (-3, ts.Hours, "Hours");
399                 Assert.AreEqual (-14, ts.Minutes, "Minutes");
400                 Assert.AreEqual (-8, ts.Seconds, "Seconds");
401                 Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
402                 Assert.AreEqual (-21474836480000000, ts.Ticks, "Ticks");
403         }
404
405         [Test]
406         public void MaxMilliseconds () 
407         {
408                 TimeSpan ts = new TimeSpan (0, 0, 0, 0, Int32.MaxValue);
409                 Assert.AreEqual (24, ts.Days, "Days");
410                 Assert.AreEqual (20, ts.Hours, "Hours");
411                 Assert.AreEqual (31, ts.Minutes, "Minutes");
412                 Assert.AreEqual (23, ts.Seconds, "Seconds");
413                 Assert.AreEqual (647, ts.Milliseconds, "Milliseconds");
414                 Assert.AreEqual (21474836470000, ts.Ticks, "Ticks");
415         }
416
417         [Test]
418         public void MinMilliseconds () 
419         {
420                 TimeSpan ts = new TimeSpan (0, 0, 0, 0, Int32.MinValue);
421                 Assert.AreEqual (-24, ts.Days, "Days");
422                 Assert.AreEqual (-20, ts.Hours, "Hours");
423                 Assert.AreEqual (-31, ts.Minutes, "Minutes");
424                 Assert.AreEqual (-23, ts.Seconds, "Seconds");
425                 Assert.AreEqual (-648, ts.Milliseconds, "Milliseconds");
426                 Assert.AreEqual (-21474836480000, ts.Ticks, "Ticks");
427         }
428
429         [Test]
430         public void NegativeTimeSpan () 
431         {
432                 TimeSpan ts = new TimeSpan (-23, -59, -59);
433                 Assert.AreEqual (0, ts.Days, "Days");
434                 Assert.AreEqual (-23, ts.Hours, "Hours");
435                 Assert.AreEqual (-59, ts.Minutes, "Minutes");
436                 Assert.AreEqual (-59, ts.Seconds, "Seconds");
437                 Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
438                 Assert.AreEqual (-863990000000, ts.Ticks, "Ticks");
439         }
440
441         public void TestProperties ()
442         {
443                 TimeSpan t1 = new TimeSpan (1,2,3,4,5);
444                 TimeSpan t2 = -t1;
445
446                 Assert.AreEqual (1, t1.Days, "A1");
447                 Assert.AreEqual (2, t1.Hours, "A2");
448                 Assert.AreEqual (3, t1.Minutes, "A3");
449                 Assert.AreEqual (4, t1.Seconds, "A4");
450                 Assert.AreEqual (5, t1.Milliseconds, "A5");
451                 Assert.AreEqual (-1, t2.Days, "A6");
452                 Assert.AreEqual (-2, t2.Hours, "A7");
453                 Assert.AreEqual (-3, t2.Minutes, "A8");
454                 Assert.AreEqual (-4, t2.Seconds, "A9");
455                 Assert.AreEqual (-5, t2.Milliseconds, "A10");
456         }
457
458         public void TestAdd ()
459         {
460                 TimeSpan t1 = new TimeSpan (2,3,4,5,6);
461                 TimeSpan t2 = new TimeSpan (1,2,3,4,5);
462                 TimeSpan t3 = t1 + t2;
463                 TimeSpan t4 = t1.Add (t2);
464                 TimeSpan t5;
465                 bool exception;
466
467                 Assert.AreEqual (3, t3.Days, "A1");
468                 Assert.AreEqual (5, t3.Hours, "A2");
469                 Assert.AreEqual (7, t3.Minutes, "A3");
470                 Assert.AreEqual (9, t3.Seconds, "A4");
471                 Assert.AreEqual (11, t3.Milliseconds, "A5");
472                 Assert.AreEqual ("3.05:07:09.0110000", t4.ToString (), "A6");
473                 try
474                 {
475                         t5 = TimeSpan.MaxValue + new TimeSpan (1);                      
476                         exception = false;
477                 }
478                 catch (OverflowException)
479                 {
480                         exception = true;
481                 }
482                 Assert.IsTrue (exception, "A7");
483         }
484
485         public void TestCompare ()
486         {
487                 TimeSpan t1 = new TimeSpan (-1);
488                 TimeSpan t2 = new TimeSpan (1);
489                 int res;
490                 bool exception;
491
492                 Assert.AreEqual (-1, TimeSpan.Compare (t1, t2), "A1");
493                 Assert.AreEqual (1, TimeSpan.Compare (t2, t1), "A2");
494                 Assert.AreEqual (0, TimeSpan.Compare (t2, t2), "A3");
495                 Assert.AreEqual (-1, TimeSpan.Compare (TimeSpan.MinValue, TimeSpan.MaxValue), "A4");
496                 Assert.AreEqual (-1, t1.CompareTo (t2), "A5");
497                 Assert.AreEqual (1, t2.CompareTo (t1), "A6");
498                 Assert.AreEqual (0, t2.CompareTo (t2), "A7");
499                 Assert.AreEqual (-1, TimeSpan.Compare (TimeSpan.MinValue, TimeSpan.MaxValue), "A8");
500
501                 Assert.AreEqual (1, TimeSpan.Zero.CompareTo (null), "A9");
502                 
503                 try
504                 {
505                         res = TimeSpan.Zero.CompareTo("");
506                         exception = false;      
507                 }
508                 catch (ArgumentException)
509                 {
510                         exception = true;
511                 }
512                 Assert.IsTrue (exception, "A10");
513
514                 Assert.AreEqual (false, t1 == t2, "A11");
515                 Assert.AreEqual (false, t1 > t2, "A12");
516                 Assert.AreEqual (false, t1 >= t2, "A13");
517                 Assert.AreEqual (true, t1 != t2, "A14");
518                 Assert.AreEqual (true, t1 < t2, "A15");
519                 Assert.AreEqual (true, t1 <= t2, "A16");
520         }
521
522         [Test]
523         [ExpectedException (typeof (OverflowException))]
524         public void NoNegateMinValue() {
525                 TimeSpan t1 = TimeSpan.MinValue.Negate ();
526         }
527
528         public void TestNegateAndDuration ()
529         {
530                 TimeSpan t1;
531                 bool exception;
532
533                 Assert.AreEqual ("-00:00:00.0012345", new TimeSpan (12345).Negate ().ToString (), "A1");
534                 Assert.AreEqual ("00:00:00.0012345", new TimeSpan (-12345).Duration ().ToString (), "A2");
535                         
536                 try
537                 {
538                         t1 = TimeSpan.MinValue.Duration ();
539                         exception = false;
540                 }
541                 catch (OverflowException) {
542                         exception = true;
543                 }
544                 Assert.IsTrue (exception, "A4");
545
546                 Assert.AreEqual ("-00:00:00.0000077", (-(new TimeSpan (77))).ToString (), "A5");
547                 Assert.AreEqual ("00:00:00.0000077", (+(new TimeSpan(77))).ToString(), "A6");
548         }
549
550         public void TestEquals ()
551         {
552                 TimeSpan t1 = new TimeSpan (1);
553                 TimeSpan t2 = new TimeSpan (2);
554                 string s = "justastring";
555
556                 Assert.AreEqual (true, t1.Equals (t1), "A1");
557                 Assert.AreEqual (false, t1.Equals (t2), "A2");
558                 Assert.AreEqual (false, t1.Equals (s), "A3");
559                 Assert.AreEqual (false, t1.Equals (null), "A4");
560                 Assert.AreEqual (true, TimeSpan.Equals (t1, t1), "A5");
561                 Assert.AreEqual (false, TimeSpan.Equals (t1, t2), "A6");
562                 Assert.AreEqual (false, TimeSpan.Equals (t1, null), "A7");
563                 Assert.AreEqual (false, TimeSpan.Equals (t1, s), "A8");
564                 Assert.AreEqual (false, TimeSpan.Equals (s, t2), "A9");
565                 Assert.AreEqual (true, TimeSpan.Equals (null, null), "A10");
566         }
567
568         public void TestFromXXXX ()
569         {
570                 Assert.AreEqual ("12.08:16:48", TimeSpan.FromDays (12.345).ToString (), "A1");
571                 Assert.AreEqual ("12:20:42", TimeSpan.FromHours (12.345).ToString (), "A2");
572                 Assert.AreEqual ("00:12:20.7000000", TimeSpan.FromMinutes (12.345).ToString (), "A3");
573                 Assert.AreEqual ("00:00:12.3450000", TimeSpan.FromSeconds (12.345).ToString (), "A4");
574                 Assert.AreEqual ("00:00:00.0120000", TimeSpan.FromMilliseconds (12.345).ToString (), "A5");
575                 Assert.AreEqual ("00:00:00.0012345", TimeSpan.FromTicks (12345).ToString (), "A6");
576         }
577
578         [Test]
579         [ExpectedException (typeof (OverflowException))]
580         public void FromDays_MinValue ()
581         {
582                 TimeSpan.FromDays (Double.MinValue);
583         }
584
585         [Test]
586         [ExpectedException (typeof (OverflowException))]
587         public void FromDays_MaxValue ()
588         {
589                 TimeSpan.FromDays (Double.MaxValue);
590         }
591
592         [Test]
593         [ExpectedException (typeof (ArgumentException))]
594         public void FromDays_NaN ()
595         {
596                 TimeSpan.FromDays (Double.NaN);
597         }
598
599         [Test]
600         [ExpectedException (typeof (OverflowException))]
601         public void FromDays_PositiveInfinity ()
602         {
603                 // LAMESPEC: Document to return TimeSpan.MaxValue
604                 Assert.AreEqual (TimeSpan.MaxValue, TimeSpan.FromDays (Double.PositiveInfinity));
605         }
606
607         [Test]
608         [ExpectedException (typeof (OverflowException))]
609         public void FromDays_NegativeInfinity ()
610         {
611                 // LAMESPEC: Document to return TimeSpan.MinValue
612                 Assert.AreEqual (TimeSpan.MinValue, TimeSpan.FromDays (Double.NegativeInfinity));
613         }
614
615         [Test]
616         [ExpectedException (typeof (OverflowException))]
617         public void FromHours_MinValue ()
618         {
619                 TimeSpan.FromHours (Double.MinValue);
620         }
621
622         [Test]
623         [ExpectedException (typeof (OverflowException))]
624         public void FromHours_MaxValue ()
625         {
626                 TimeSpan.FromHours (Double.MaxValue);
627         }
628
629         [Test]
630         [ExpectedException (typeof (ArgumentException))]
631         public void FromHours_NaN ()
632         {
633                 TimeSpan.FromHours (Double.NaN);
634         }
635
636         [Test]
637         [ExpectedException (typeof (OverflowException))]
638         public void FromHours_PositiveInfinity ()
639         {
640                 // LAMESPEC: Document to return TimeSpan.MaxValue
641                 Assert.AreEqual (TimeSpan.MaxValue, TimeSpan.FromHours (Double.PositiveInfinity));
642         }
643
644         [Test]
645         [ExpectedException (typeof (OverflowException))]
646         public void FromHours_NegativeInfinity ()
647         {
648                 // LAMESPEC: Document to return TimeSpan.MinValue
649                 Assert.AreEqual (TimeSpan.MinValue, TimeSpan.FromHours (Double.NegativeInfinity));
650         }
651
652         [Test]
653         [ExpectedException (typeof (OverflowException))]
654         public void FromMilliseconds_MinValue ()
655         {
656                 TimeSpan.FromMilliseconds (Double.MinValue);
657         }
658
659         [Test]
660         [ExpectedException (typeof (OverflowException))]
661         public void FromMilliseconds_MaxValue ()
662         {
663                 TimeSpan.FromMilliseconds (Double.MaxValue);
664         }
665
666         [Test]
667         [ExpectedException (typeof (ArgumentException))]
668         public void FromMilliseconds_NaN ()
669         {
670                 TimeSpan.FromMilliseconds (Double.NaN);
671         }
672
673         [Test]
674         [ExpectedException (typeof (OverflowException))]
675         public void FromMilliseconds_PositiveInfinity ()
676         {
677                 // LAMESPEC: Document to return TimeSpan.MaxValue
678                 Assert.AreEqual (TimeSpan.MaxValue, TimeSpan.FromMilliseconds (Double.PositiveInfinity));
679         }
680
681         [Test]
682         [ExpectedException (typeof (OverflowException))]
683         public void FromMilliseconds_NegativeInfinity ()
684         {
685                 // LAMESPEC: Document to return TimeSpan.MinValue
686                 Assert.AreEqual (TimeSpan.MinValue, TimeSpan.FromMilliseconds (Double.NegativeInfinity));
687         }
688
689         [Test]
690         [ExpectedException (typeof (OverflowException))]
691         public void FromMinutes_MinValue ()
692         {
693                 TimeSpan.FromMinutes (Double.MinValue);
694         }
695
696         [Test]
697         [ExpectedException (typeof (OverflowException))]
698         public void FromMinutes_MaxValue ()
699         {
700                 TimeSpan.FromMinutes (Double.MaxValue);
701         }
702
703         [Test]
704         [ExpectedException (typeof (ArgumentException))]
705         public void FromMinutes_NaN ()
706         {
707                 TimeSpan.FromMinutes (Double.NaN);
708         }
709
710         [Test]
711         [ExpectedException (typeof (OverflowException))]
712         public void FromMinutes_PositiveInfinity ()
713         {
714                 // LAMESPEC: Document to return TimeSpan.MaxValue
715                 Assert.AreEqual (TimeSpan.MaxValue, TimeSpan.FromMinutes (Double.PositiveInfinity));
716         }
717
718         [Test]
719         [ExpectedException (typeof (OverflowException))]
720         public void FromMinutes_NegativeInfinity ()
721         {
722                 // LAMESPEC: Document to return TimeSpan.MinValue
723                 Assert.AreEqual (TimeSpan.MinValue, TimeSpan.FromMinutes (Double.NegativeInfinity));
724         }
725
726         [Test]
727         [ExpectedException (typeof (OverflowException))]
728         public void FromSeconds_MinValue ()
729         {
730                 TimeSpan.FromSeconds (Double.MinValue);
731         }
732
733         [Test]
734         [ExpectedException (typeof (OverflowException))]
735         public void FromSeconds_MaxValue ()
736         {
737                 TimeSpan.FromSeconds (Double.MaxValue);
738         }
739
740         [Test]
741         [ExpectedException (typeof (ArgumentException))]
742         public void FromSeconds_NaN ()
743         {
744                 TimeSpan.FromSeconds (Double.NaN);
745         }
746
747         [Test]
748         [ExpectedException (typeof (OverflowException))]
749         public void FromSeconds_PositiveInfinity ()
750         {
751                 // LAMESPEC: Document to return TimeSpan.MaxValue
752                 Assert.AreEqual (TimeSpan.MaxValue, TimeSpan.FromSeconds (Double.PositiveInfinity));
753         }
754
755         [Test]
756         [ExpectedException (typeof (OverflowException))]
757         public void FromSeconds_NegativeInfinity ()
758         {
759                 // LAMESPEC: Document to return TimeSpan.MinValue
760                 Assert.AreEqual (TimeSpan.MinValue, TimeSpan.FromSeconds (Double.NegativeInfinity));
761         }
762
763         public void TestGetHashCode ()
764         {
765                 Assert.AreEqual (77, new TimeSpan (77).GetHashCode (), "A1");
766         }
767
768         private void ParseHelper (string s, bool expectFormat, bool expectOverflow, string expect)
769         {
770                 bool formatException = false;
771                 bool overflowException = false;
772                 string result = "junk ";
773
774                 try {
775                         result =  TimeSpan.Parse (s).ToString ();
776                 }
777                 catch (OverflowException) {
778                         overflowException = true;
779                 }
780                 catch (FormatException) {
781                         formatException = true;
782                 }
783                 Assert.AreEqual (expectFormat, formatException, "A1");
784                 Assert.AreEqual (expectOverflow, overflowException, "A2");
785
786                 if (!expectOverflow && !expectFormat) {
787                         Assert.AreEqual (expect, result, "A3");
788                 }
789         }
790
791         [Test]
792         public void TestParse ()
793         {
794                 ParseHelper (" 13:45:15 ",false, false, "13:45:15");
795                 ParseHelper (" -1:2:3 ", false, false, "-01:02:03");
796
797 #if NET_4_0
798                 // In 4.0 when the first part is out of range, it parses it as day.
799                 ParseHelper (" 25:11:12 ", false, false, "25.11:12:00");
800                 ParseHelper (" 24:11:12 ", false, false, "24.11:12:00");
801                 ParseHelper (" 23:11:12 ", false, false, "23:11:12");
802 #else
803                 ParseHelper (" 25:0:0 ",false, true, "dontcare");
804 #endif
805
806                 ParseHelper ("-21.23:59:59.9999999", false, false, "-21.23:59:59.9999999");
807                 ParseHelper ("10:12  ", false, false, "10:12:00");
808                 ParseHelper ("aaa", true, false, "dontcare");
809
810                 ParseHelper ("100000000000000.1:1:1", false, true, "dontcare");
811                 ParseHelper ("24:60:60", false, true, "dontcare");
812
813 #if NET_4_0
814                 // In 4.0 we get an overflow exception here, as opposed to a successful operation in 2.0,
815                 // due to more than one preceding zero.
816                 ParseHelper ("0001:0002:0003.12     ", false, true, "dontcare");
817                 ParseHelper ("01:02:03.12    ", false, false, "01:02:03.1200000");
818 #else
819                 ParseHelper ("0001:0002:0003.12     ", false, false, "01:02:03.1200000");
820 #endif
821
822 #if NET_4_0
823                 // In 4.0 when a section has more than 7 digits an OverflowException is thrown.
824                 ParseHelper (" 1:2:3:12345678 ", false, true, "dontcare");
825 #else
826                 ParseHelper (" 1:2:3:12345678 ", true, false, "dontcare"); 
827 #endif
828
829 #if NET_4_0             
830                 ParseHelper ("10:11:12:13", false, false, "10.11:12:13"); // Days using : instead of . as separator
831                 ParseHelper ("10.11", true, false, "dontcare"); // days+hours is invalid
832
833                 // Force the use of french culture -which is using a non common NumberDecimalSeparator-
834                 // as current culture, to show that the Parse method is *actually* being culture sensitive
835                 // *and* also keeping the compatibility with '.'
836                 CultureInfo french_culture = CultureInfo.GetCultureInfo ("fr-FR");
837                 CultureInfo prev_culture = CultureInfo.CurrentCulture;
838                 try {
839                         Thread.CurrentThread.CurrentCulture = french_culture;
840                         ParseHelper ("10:10:10,006", false, false, "10:10:10.0060000");
841                         ParseHelper ("10:10:10.006", false, false, "10:10:10.0060000");
842                 } finally {
843                         // restore culture
844                         Thread.CurrentThread.CurrentCulture = prev_culture;
845                 }
846 #endif
847         }
848
849         // LAMESPEC: timespan in documentation is wrong - hh:mm:ss isn't mandatory
850         [Test]
851         public void Parse_Days_WithoutColon () 
852         {
853                 TimeSpan ts = TimeSpan.Parse ("1");
854                 Assert.AreEqual (1, ts.Days, "Days");
855         }
856
857         public void TestSubstract ()
858         {
859                 TimeSpan t1 = new TimeSpan (2,3,4,5,6);
860                 TimeSpan t2 = new TimeSpan (1,2,3,4,5);
861                 TimeSpan t3 = t1 - t2;
862                 TimeSpan t4 = t1.Subtract (t2);
863                 TimeSpan t5;
864                 bool exception;
865
866                 Assert.AreEqual ("1.01:01:01.0010000", t3.ToString (), "A1");
867                 Assert.AreEqual ("1.01:01:01.0010000", t4.ToString (), "A2");
868                 try {
869                         t5 = TimeSpan.MinValue - new TimeSpan (1);
870                         exception = false;
871                 }
872                 catch (OverflowException) {
873                         exception = true;
874                 }
875                 Assert.IsTrue (exception, "A3");
876         }
877
878         public void TestToString () 
879         {
880                 TimeSpan t1 = new TimeSpan (1,2,3,4,5);
881                 TimeSpan t2 = -t1;
882                 
883                 Assert.AreEqual ("1.02:03:04.0050000", t1.ToString (), "A1");
884                 Assert.AreEqual ("-1.02:03:04.0050000", t2.ToString (), "A2");
885                 Assert.AreEqual ("10675199.02:48:05.4775807", TimeSpan.MaxValue.ToString (), "A3");
886                 Assert.AreEqual ("-10675199.02:48:05.4775808", TimeSpan.MinValue.ToString (), "A4");
887         }
888
889         [Test]
890         public void ToString_Constants () 
891         {
892                 Assert.AreEqual ("00:00:00", TimeSpan.Zero.ToString (), "Zero");
893                 Assert.AreEqual ("10675199.02:48:05.4775807", TimeSpan.MaxValue.ToString (), "MaxValue");
894                 Assert.AreEqual ("-10675199.02:48:05.4775808", TimeSpan.MinValue.ToString (), "MinValue");
895         }
896
897         [Test]
898         public void Parse_InvalidValuesAndFormat_ExceptionOrder () 
899         {
900                 // hours should be between 0 and 23 but format is also invalid (too many dots)
901                 // In 2.0 overflow as precedence over format, but not in 4.0
902 #if NET_4_0
903                 try {
904                         TimeSpan.Parse ("0.99.99.0");
905                         Assert.Fail ("#A1");
906                 } catch (FormatException) {
907                 }
908 #else
909                 try {
910                         TimeSpan.Parse ("0.99.99.0");
911                         Assert.Fail ("#A1");
912                 } catch (OverflowException) {
913                 }
914 #endif
915         }
916
917         [Test]
918         public void Parse_MinMaxValues () 
919         {
920                 Assert.AreEqual (TimeSpan.MaxValue, TimeSpan.Parse ("10675199.02:48:05.4775807"), "MaxValue");
921                 Assert.AreEqual (TimeSpan.MinValue, TimeSpan.Parse ("-10675199.02:48:05.4775808"), "MinValue");
922         }
923
924         [Test]
925         [ExpectedException (typeof (OverflowException))]
926         public void Parse_OverMaxValue() 
927         {
928                 TimeSpan.Parse ("10675199.02:48:05.4775808");
929         }
930
931         [Test]
932         [ExpectedException (typeof (OverflowException))]
933         public void Parse_UnderMinValue() 
934         {
935                 TimeSpan.Parse ("-10675199.02:48:05.4775809");
936         }
937
938         [Test]
939         public void ParseMissingSeconds ()
940         {
941                 // as seen in ML for http://resources.esri.com/arcgisserver/apis/silverlight/
942                 TimeSpan ts = TimeSpan.Parse ("0:0:.75");
943
944                 Assert.AreEqual (0, ts.Days, "Days");
945                 Assert.AreEqual (0, ts.Hours, "Hours");
946                 Assert.AreEqual (750, ts.Milliseconds, "Milliseconds");
947                 Assert.AreEqual (0, ts.Minutes, "Minutes");
948                 Assert.AreEqual (0, ts.Seconds, "Seconds");
949                 Assert.AreEqual (7500000, ts.Ticks, "Ticks");
950                 Assert.AreEqual (0.0000086805555555555555, ts.TotalDays, 0.00000000000000001, "TotalDays");
951                 Assert.AreEqual (0.00020833333333333332, ts.TotalHours, 0.00000000000000001, "TotalHours");
952                 Assert.AreEqual (750.0, ts.TotalMilliseconds, "TotalMilliseconds");
953                 Assert.AreEqual (0.0125, ts.TotalMinutes, "TotalMinutes");
954                 Assert.AreEqual (0.75, ts.TotalSeconds, "TotalSeconds");
955         }
956
957         // 'Ported' the Parse test to use TryParse
958         [Test]
959         public void TryParse ()
960         {
961                 TimeSpan result;
962
963                 Assert.AreEqual (true, TimeSpan.TryParse (" 13:45:15 ", out result), "#A1");
964                 Assert.AreEqual ("13:45:15", result.ToString (), "#A2");
965
966                 Assert.AreEqual (true, TimeSpan.TryParse (" -1:2:3 ", out result), "#B1");
967                 Assert.AreEqual ("-01:02:03", result.ToString (), "#B2");
968
969                 Assert.AreEqual (false, TimeSpan.TryParse ("aaa", out result), "#C2");
970
971                 Assert.AreEqual (true, TimeSpan.TryParse ("-21.23:59:59.9999999", out result), "#D1");
972                 Assert.AreEqual ("-21.23:59:59.9999999", result.ToString (), "#D2");
973
974                 Assert.AreEqual (false, TimeSpan.TryParse ("100000000000000.1:1:1", out result), "#E1");
975                 Assert.AreEqual (false, TimeSpan.TryParse ("24:60:60", out result), "#E2");
976
977 #if NET_4_0
978                 Assert.AreEqual (false, TimeSpan.TryParse ("0001:0002:0003.12     ", out result), "#F1");
979 #else
980                 Assert.AreEqual (true, TimeSpan.TryParse ("0001:0002:0003.12     ", out result), "#F1");
981                 Assert.AreEqual ("01:02:03.1200000", result.ToString (), "#F2");
982 #endif
983
984                 Assert.AreEqual (false, TimeSpan.TryParse (" 1:2:3:12345678 ", out result), "#G1");
985
986                 // Min and Max values
987                 Assert.AreEqual (true, TimeSpan.TryParse ("10675199.02:48:05.4775807", out result), "MaxValue#1");
988                 Assert.AreEqual (TimeSpan.MaxValue, result, "MaxValue#2");
989                 Assert.AreEqual (true, TimeSpan.TryParse ("-10675199.02:48:05.4775808", out result), "MinValue#1");
990                 Assert.AreEqual (TimeSpan.MinValue, result, "MinValue#2");
991
992 #if NET_4_0
993                 // Force the use of french culture -which is using a non common NumberDecimalSeparator-
994                 // as current culture, to show that the Parse method is *actually* being culture sensitive
995                 CultureInfo french_culture = CultureInfo.GetCultureInfo ("fr-FR");
996                 CultureInfo prev_culture = CultureInfo.CurrentCulture;
997                 result = new TimeSpan (0, 10, 10, 10, 6);
998                 try {
999                         Thread.CurrentThread.CurrentCulture = french_culture;
1000                         Assert.AreEqual (true, TimeSpan.TryParse ("10:10:10,006", out result), "#CultureSensitive1");
1001                         Assert.AreEqual ("10:10:10.0060000", result.ToString (), "#CultureSensitive2");
1002                 } finally {
1003                         // restore culture
1004                         Thread.CurrentThread.CurrentCulture = prev_culture;
1005                 }
1006 #endif
1007         }
1008
1009         [Test]
1010         public void TryParseErrors ()
1011         {
1012                 TimeSpan result;
1013
1014                 Assert.AreEqual (false, TimeSpan.TryParse ("0.99.99.0", out result), "Format#1");
1015                 Assert.AreEqual (false, TimeSpan.TryParse ("10675199.02:48:05.4775808", out result), "OverMaxValue");
1016                 Assert.AreEqual (false, TimeSpan.TryParse ("-10675199.02:48:05.4775809", out result), "UnderMinValue");
1017         }
1018
1019 #if NET_4_0
1020         [Test]
1021         public void TryParseOverloads ()
1022         { 
1023                 TimeSpan result;
1024
1025                 // We use fr-FR culture since its NumericDecimalSeparator is not the same used by
1026                 // most cultures - including the invariant one.
1027                 CultureInfo french_culture = CultureInfo.GetCultureInfo ("fr-FR");
1028                 Assert.AreEqual (true, TimeSpan.TryParse ("11:50:50,006", french_culture, out result), "#A1");
1029
1030                 // LAMESPEC - msdn states that an instance of DateTimeFormatInfo is retrieved to
1031                 // obtain culture sensitive information, but at least in the betas that's false
1032                 DateTimeFormatInfo format_info = new DateTimeFormatInfo ();
1033                 format_info.TimeSeparator = ";";
1034                 Assert.AreEqual (false, TimeSpan.TryParse ("11;50;50", format_info, out result), "#B1");
1035                 Assert.AreEqual (true, TimeSpan.TryParse ("11:50:50", format_info, out result), "#B2");
1036         }
1037
1038         [Test]
1039         public void ToStringOverloads ()
1040         {
1041                 TimeSpan ts = new TimeSpan (1, 2, 3, 4, 6);
1042
1043                 // Simple version - culture invariant
1044                 Assert.AreEqual ("1.02:03:04.0060000", ts.ToString (), "#A1");
1045                 Assert.AreEqual ("1.02:03:04.0060000", ts.ToString ("c"), "#A2");
1046                 Assert.AreEqual ("1.02:03:04.0060000", ts.ToString (null), "#A3");
1047                 Assert.AreEqual ("1.02:03:04.0060000", ts.ToString (String.Empty), "#A4");
1048
1049                 //
1050                 // IFormatProvider ones - use a culture changing numeric format.
1051                 // Also, we use fr-FR as culture, since it uses some elements different to invariant culture
1052                 //
1053                 CultureInfo culture = CultureInfo.GetCultureInfo ("fr-FR");
1054
1055                 Assert.AreEqual ("1:2:03:04,006", ts.ToString ("g", culture), "#B1");
1056                 Assert.AreEqual ("1:02:03:04,0060000", ts.ToString ("G", culture), "#B2");
1057                 Assert.AreEqual ("1.02:03:04.0060000", ts.ToString ("c", culture), "#B3"); // 'c' format ignores CultureInfo
1058
1059                 ts = new TimeSpan (4, 5, 6);
1060                 Assert.AreEqual ("4:05:06", ts.ToString ("g", culture), "#C1");
1061                 Assert.AreEqual ("0:04:05:06,0000000", ts.ToString ("G", culture), "#C2");
1062         }
1063
1064         [Test]
1065         public void ToStringOverloadsErrors ()
1066         {
1067                 TimeSpan ts = new TimeSpan (10, 10, 10);
1068                 string result;
1069
1070                 try {
1071                         result = ts.ToString ("non-valid");
1072                         Assert.Fail ("#1");
1073                 } catch (FormatException) {
1074                 }
1075
1076                 try {
1077                         result = ts.ToString ("C");
1078                         Assert.Fail ("#2");
1079                 } catch (FormatException) {
1080                 }
1081
1082                 // This is suppoused to work, but the docs are wrong.
1083                 try {
1084                         result = ts.ToString ("t");
1085                         Assert.Fail ("#3");
1086                 } catch (FormatException) {
1087                 }
1088         }
1089 #endif
1090 }
1091
1092 }