~ubuntu-branches/ubuntu/utopic/mono/utopic

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
//
// TimeSpanTest.cs - NUnit Test Cases for the System.TimeSpan struct
//
// Authors:
//	Duco Fijma (duco@lorentz.xs4all.nl)
//	Sebastien Pouliot  <sebastien@ximian.com>
//
// (C) 2001 Duco Fijma
// Copyright (C) 2004 Novell (http://www.novell.com)
//

using NUnit.Framework;
using System;
using System.Globalization;
using System.Threading;

namespace MonoTests.System
{

[TestFixture]
public class TimeSpanTest {

	private void Debug (TimeSpan ts) 
	{
		Console.Out.WriteLine ("Days {0}", ts.Days);
		Console.Out.WriteLine ("Hours {0}", ts.Hours);
		Console.Out.WriteLine ("Minutes {0}", ts.Minutes);
		Console.Out.WriteLine ("Seconds {0}", ts.Seconds);
		Console.Out.WriteLine ("Milliseconds {0}", ts.Milliseconds);
		Console.Out.WriteLine ("Ticks {0}", ts.Ticks);
	}

	public void TestCtors ()
	{
		TimeSpan t1 = new TimeSpan (1234567890);

		Assert.AreEqual ("00:02:03.4567890", t1.ToString (), "A1");
		t1 = new TimeSpan (1,2,3);
		Assert.AreEqual ("01:02:03", t1.ToString (), "A2");
		t1 = new TimeSpan (1,2,3,4);
		Assert.AreEqual ("1.02:03:04", t1.ToString (), "A3");
		t1 = new TimeSpan (1,2,3,4,5);
		Assert.AreEqual ("1.02:03:04.0050000", t1.ToString (), "A4");
		t1 = new TimeSpan (-1,2,-3,4,-5);
		Assert.AreEqual ("-22:02:56.0050000", t1.ToString (), "A5");
		t1 = new TimeSpan (0,25,0,0,0);
		Assert.AreEqual ("1.01:00:00", t1.ToString (), "A6");
        }

	[Test]
	[ExpectedException (typeof (ArgumentOutOfRangeException))]
	public void DaysOverflow () 
	{
		int days = (int) (Int64.MaxValue / TimeSpan.TicksPerDay) + 1;
		TimeSpan ts = new TimeSpan (days, 0, 0, 0, 0);
	}

	[Test]
#if NET_2_0
	[ExpectedException (typeof (ArgumentOutOfRangeException))]
	[Category ("NotWorking")]
#endif
	public void TemporaryOverflow () 
	{
		// calculating part of this results in overflow (days)
		// but the negative hours, minutes, seconds & ms correct this
		int days = (int) (Int64.MaxValue / TimeSpan.TicksPerDay) + 1;
		TimeSpan ts = new TimeSpan (days, Int32.MinValue, Int32.MinValue, Int32.MinValue, Int32.MinValue);
		Assert.AreEqual (10650320, ts.Days, "Days");
		Assert.AreEqual (0, ts.Hours, "Hours");
		Assert.AreEqual (14, ts.Minutes, "Minutes");
		Assert.AreEqual (28, ts.Seconds, "Seconds");
		Assert.AreEqual (352, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (9201876488683520000, ts.Ticks, "Ticks");
	}

	[Test]
#if NET_2_0
	[ExpectedException (typeof (ArgumentOutOfRangeException))]
	[Category ("NotWorking")]
#endif
	public void NoOverflowInHoursMinsSecondsMS () 
	{
		TimeSpan ts = new TimeSpan (0, Int32.MaxValue, Int32.MaxValue, Int32.MaxValue, Int32.MaxValue);
		Assert.AreEqual (24879, ts.Days, "Days");
		Assert.AreEqual (22, ts.Hours, "Hours");
		Assert.AreEqual (44, ts.Minutes, "Minutes");
		Assert.AreEqual (30, ts.Seconds, "Seconds");
		Assert.AreEqual (647, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (21496274706470000, ts.Ticks, "Ticks");
	}

	[Test]
	[ExpectedException (typeof (ArgumentOutOfRangeException))]
	public void MaxDays () 
	{
		new TimeSpan (Int32.MaxValue, 0, 0, 0, 0);
	}

	[Test]
	[ExpectedException (typeof (ArgumentOutOfRangeException))]
	public void MinDays () 
	{
		new TimeSpan (Int32.MinValue, 0, 0, 0, 0);
	}

	[Test]
	[Ignore ("too long")]
	public void MaxHours_TooLong () 
	{
		// LAMESPEC: the highest hours are "special"
		for (int i=0; i < 596523; i++) {
			TimeSpan ts = new TimeSpan (0, Int32.MaxValue - i, 0, 0, 0);
			int h = i + 1;
			string prefix = i.ToString () + '-';
			Assert.AreEqual (-(h / 24), ts.Days, prefix + "Days");
			Assert.AreEqual (-(h % 24), ts.Hours, prefix + "Hours");
			Assert.AreEqual (0, ts.Minutes, prefix + "Minutes");
			Assert.AreEqual (0, ts.Seconds, prefix + "Seconds");
			Assert.AreEqual (0, ts.Milliseconds, prefix + "Milliseconds");
			Assert.AreEqual (-36000000000 * h, ts.Ticks, prefix + "Ticks");
		}
	}

	[Test]
#if NET_2_0
	[ExpectedException (typeof (ArgumentOutOfRangeException))]
	[Category ("NotWorking")]
#endif
	public void MaxHours () 
	{
		// LAMESPEC: the highest hours are "special"
		TimeSpan ts = new TimeSpan (0, Int32.MaxValue, 0, 0, 0);
		Assert.AreEqual (0, ts.Days, "Max-Days");
		Assert.AreEqual (-1, ts.Hours, "Max-Hours");
		Assert.AreEqual (0, ts.Minutes, "Max-Minutes");
		Assert.AreEqual (0, ts.Seconds, "Max-Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Max-Milliseconds");
		Assert.AreEqual (-36000000000, ts.Ticks, "Max-Ticks");

		ts = new TimeSpan (0, Int32.MaxValue - 596522, 0, 0, 0);
		Assert.AreEqual (-24855, ts.Days, "Days");
		Assert.AreEqual (-3, ts.Hours, "Hours");
		Assert.AreEqual (0, ts.Minutes, "Minutes");
		Assert.AreEqual (0, ts.Seconds, "Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (-21474828000000000, ts.Ticks, "Ticks");
	}

	[Test]
#if NET_2_0
	[ExpectedException (typeof (ArgumentOutOfRangeException))]
	[Category ("NotWorking")]
#endif
	public void MaxHours_BreakPoint () 
	{
		TimeSpan ts = new TimeSpan (0, Int32.MaxValue - 596523, 0, 0, 0);
		Assert.AreEqual (24855, ts.Days, "Days");
		Assert.AreEqual (2, ts.Hours, "Hours");
		Assert.AreEqual (28, ts.Minutes, "Minutes");
		Assert.AreEqual (16, ts.Seconds, "Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (21474808960000000, ts.Ticks, "Ticks");
	}

	[Test]
	[Ignore ("too long")]
	public void MinHours_TooLong () 
	{
		// LAMESPEC: the lowest hours are "special"
		for (int i=Int32.MinValue; i < -2146887124; i++) {
			TimeSpan ts = new TimeSpan (0, i, 0, 0, 0);
			int h = i + Int32.MaxValue + 1;
			string prefix = i.ToString () + '-';
			Assert.AreEqual ((h / 24), ts.Days, prefix + "Days");
			Assert.AreEqual ((h % 24), ts.Hours, prefix + "Hours");
			Assert.AreEqual (0, ts.Minutes, prefix + "Minutes");
			Assert.AreEqual (0, ts.Seconds, prefix + "Seconds");
			Assert.AreEqual (0, ts.Milliseconds, prefix + "Milliseconds");
			Assert.AreEqual (36000000000 * h, ts.Ticks, prefix + "Ticks");
		}
	}

	[Test]
#if NET_2_0
	[Category ("NotWorking")]
#endif
	public void MinHours () 
	{
#if NET_2_0
		TimeSpan ts = new TimeSpan (0, -256204778, 0, 0, 0);
		Assert.AreEqual (-10675199, ts.Days, "Days");
		Assert.AreEqual (-2, ts.Hours, "Hours");
		Assert.AreEqual (0, ts.Minutes, "Minutes");
		Assert.AreEqual (0, ts.Seconds, "Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (-9223372008000000000, ts.Ticks, "Ticks");
#else
		// LAMESPEC: the lowest hours are "special"
		TimeSpan ts = new TimeSpan (0, Int32.MinValue, 0, 0, 0);
		Assert.AreEqual (0, ts.Days, "Min-Days");
		Assert.AreEqual (0, ts.Hours, "Min-Hours");
		Assert.AreEqual (0, ts.Minutes, "Min-Minutes");
		Assert.AreEqual (0, ts.Seconds, "Min-Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Min-Milliseconds");
		Assert.AreEqual (0, ts.Ticks, "Min-Ticks");

		ts = new TimeSpan (0, -2146887125, 0, 0, 0);
		Assert.AreEqual (24855, ts.Days, "Days");
		Assert.AreEqual (3, ts.Hours, "Hours");
		Assert.AreEqual (0, ts.Minutes, "Minutes");
		Assert.AreEqual (0, ts.Seconds, "Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (21474828000000000, ts.Ticks, "Ticks");
#endif
	}

	[Test]
#if NET_2_0
	[ExpectedException (typeof (ArgumentOutOfRangeException))]
	[Category ("NotWorking")]
#endif
	public void MinHours_BreakPoint () 
	{
		TimeSpan ts = new TimeSpan (0, -2146887124, 0, 0, 0);
		Assert.AreEqual (-24855, ts.Days, "Days");
		Assert.AreEqual (-2, ts.Hours, "Hours");
		Assert.AreEqual (-28, ts.Minutes, "Minutes");
		Assert.AreEqual (-16, ts.Seconds, "Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (-21474808960000000, ts.Ticks, "Ticks");
	}

	[Test]
	[Ignore ("too long")]
	public void MaxMinutes_TooLong () 
	{
		// LAMESPEC: the highest minutes are "special"
		for (int i=0; i < 35791394; i++) {
			TimeSpan ts = new TimeSpan (0, 0, Int32.MaxValue - i, 0, 0);
			long h = -(i + 1);
			string prefix = i.ToString () + '-';
			Assert.AreEqual ((h / 1440), ts.Days, prefix + "Days");
			Assert.AreEqual (((h / 60) % 24), ts.Hours, prefix + "Hours");
			Assert.AreEqual ((h % 60), ts.Minutes, prefix + "Minutes");
			Assert.AreEqual (0, ts.Seconds, prefix + "Seconds");
			Assert.AreEqual (0, ts.Milliseconds, prefix + "Milliseconds");
			Assert.AreEqual ((600000000L * h), ts.Ticks, prefix + "Ticks");
		}
	}

	[Test]
#if NET_2_0
	[Category ("NotWorking")]
#endif
	public void MaxMinutes () 
	{
		TimeSpan ts;
#if NET_2_0
		ts = new TimeSpan (0, 0, 256204778, 0, 0);
		Assert.AreEqual (177919, ts.Days, "Max-Days");
		Assert.AreEqual (23, ts.Hours, "Max-Hours");
		Assert.AreEqual (38, ts.Minutes, "Max-Minutes");
		Assert.AreEqual (0, ts.Seconds, "Max-Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Max-Milliseconds");
		Assert.AreEqual (153722866800000000, ts.Ticks, "Max-Ticks");
#else
		// LAMESPEC: the highest minutes are "special"
		ts = new TimeSpan (0, 0, Int32.MaxValue, 0, 0);
		Assert.AreEqual (0, ts.Days, "Max-Days");
		Assert.AreEqual (0, ts.Hours, "Max-Hours");
		Assert.AreEqual (-1, ts.Minutes, "Max-Minutes");
		Assert.AreEqual (0, ts.Seconds, "Max-Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Max-Milliseconds");
		Assert.AreEqual (-600000000, ts.Ticks, "Max-Ticks");

		ts = new TimeSpan (0, 0, Int32.MaxValue - 35791393, 0, 0);
		Assert.AreEqual (-24855, ts.Days, "Days");
		Assert.AreEqual (-3, ts.Hours, "Hours");
		Assert.AreEqual (-14, ts.Minutes, "Minutes");
		Assert.AreEqual (0, ts.Seconds, "Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (-21474836400000000, ts.Ticks, "Ticks");
#endif
	}

	[Test]
#if NET_2_0
	[ExpectedException (typeof (ArgumentOutOfRangeException))]
	[Category ("NotWorking")]
#endif
	public void MaxMinutes_BreakPoint () 
	{
		TimeSpan ts = new TimeSpan (0, Int32.MaxValue - 35791394, 0, 0, 0);
		Assert.AreEqual (0, ts.Days, "Days");
		Assert.AreEqual (0, ts.Hours, "Hours");
		Assert.AreEqual (-52, ts.Minutes, "Minutes");
		Assert.AreEqual (0, ts.Seconds, "Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (-31200000000, ts.Ticks, "Ticks");
	}

	[Test]
	[Ignore ("too long")]
	public void MinMinutes_TooLong () 
	{
		// LAMESPEC: the highest minutes are "special"
		for (int i=Int32.MinValue; i < -2111692253; i++) {
			TimeSpan ts = new TimeSpan (0, 0, i, 0, 0);
			long h = i + Int32.MaxValue + 1;
			string prefix = i.ToString () + '-';
			Assert.AreEqual ((h / 1440), ts.Days, prefix + "Days");
			Assert.AreEqual (((h / 60) % 24), ts.Hours, prefix + "Hours");
			Assert.AreEqual ((h % 60), ts.Minutes, prefix + "Minutes");
			Assert.AreEqual (0, ts.Seconds, prefix + "Seconds");
			Assert.AreEqual (0, ts.Milliseconds, prefix + "Milliseconds");
			Assert.AreEqual ((600000000L * h), ts.Ticks, prefix + "Ticks");
		}
	}

	[Test]
#if NET_2_0
	[Category ("NotWorking")]
#endif
	public void MinMinutes () 
	{
		TimeSpan ts;
#if NET_2_0
		ts = new TimeSpan (0, 0, Int32.MinValue, 0, 0);
		Assert.AreEqual (-1491308, ts.Days, "Days");
		Assert.AreEqual (-2, ts.Hours, "Hours");
		Assert.AreEqual (-8, ts.Minutes, "Minutes");
		Assert.AreEqual (0, ts.Seconds, "Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (-1288490188800000000, ts.Ticks, "Ticks");
#else
		// LAMESPEC: the highest minutes are "special"
		ts = new TimeSpan (0, 0, Int32.MinValue, 0, 0);
		Assert.AreEqual (0, ts.Days, "Min-Days");
		Assert.AreEqual (0, ts.Hours, "Min-Hours");
		Assert.AreEqual (0, ts.Minutes, "Min-Minutes");
		Assert.AreEqual (0, ts.Seconds, "Min-Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Min-Milliseconds");
		Assert.AreEqual (0, ts.Ticks, "Min-Ticks");

		ts = new TimeSpan (0, 0, -2111692254, 0, 0);
		Assert.AreEqual (24855, ts.Days, "Days");
		Assert.AreEqual (3, ts.Hours, "Hours");
		Assert.AreEqual (14, ts.Minutes, "Minutes");
		Assert.AreEqual (0, ts.Seconds, "Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (21474836400000000, ts.Ticks, "Ticks");
#endif
	}

	[Test]
#if NET_2_0
	[Category ("NotWorking")]
#endif
	public void MinMinutes_BreakPoint () 
	{
#if NET_2_0
		TimeSpan ts = new TimeSpan (0, 0, -2111692253, 0, 0);
		Assert.AreEqual (-1466452, ts.Days, "Days");
		Assert.AreEqual (-22, ts.Hours, "Hours");
		Assert.AreEqual (-53, ts.Minutes, "Minutes");
		Assert.AreEqual (-0, ts.Seconds, "Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (-1267015351800000000, ts.Ticks, "Ticks");
#else
		TimeSpan ts = new TimeSpan (0, 0, -2111692253, 0, 0);
		Assert.AreEqual (-24855, ts.Days, "Days");
		Assert.AreEqual (-3, ts.Hours, "Hours");
		Assert.AreEqual (-13, ts.Minutes, "Minutes");
		Assert.AreEqual (-16, ts.Seconds, "Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (-21474835960000000, ts.Ticks, "Ticks");
#endif
	}

	[Test]
	public void MaxSeconds () 
	{
		TimeSpan ts = new TimeSpan (0, 0, 0, Int32.MaxValue, 0);
		Assert.AreEqual (24855, ts.Days, "Days");
		Assert.AreEqual (3, ts.Hours, "Hours");
		Assert.AreEqual (14, ts.Minutes, "Minutes");
		Assert.AreEqual (7, ts.Seconds, "Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (21474836470000000, ts.Ticks, "Ticks");
	}

	[Test]
	public void MinSeconds () 
	{
		TimeSpan ts = new TimeSpan (0, 0, 0, Int32.MinValue, 0);
		Assert.AreEqual (-24855, ts.Days, "Days");
		Assert.AreEqual (-3, ts.Hours, "Hours");
		Assert.AreEqual (-14, ts.Minutes, "Minutes");
		Assert.AreEqual (-8, ts.Seconds, "Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (-21474836480000000, ts.Ticks, "Ticks");
	}

	[Test]
	public void MaxMilliseconds () 
	{
		TimeSpan ts = new TimeSpan (0, 0, 0, 0, Int32.MaxValue);
		Assert.AreEqual (24, ts.Days, "Days");
		Assert.AreEqual (20, ts.Hours, "Hours");
		Assert.AreEqual (31, ts.Minutes, "Minutes");
		Assert.AreEqual (23, ts.Seconds, "Seconds");
		Assert.AreEqual (647, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (21474836470000, ts.Ticks, "Ticks");
	}

	[Test]
	public void MinMilliseconds () 
	{
		TimeSpan ts = new TimeSpan (0, 0, 0, 0, Int32.MinValue);
		Assert.AreEqual (-24, ts.Days, "Days");
		Assert.AreEqual (-20, ts.Hours, "Hours");
		Assert.AreEqual (-31, ts.Minutes, "Minutes");
		Assert.AreEqual (-23, ts.Seconds, "Seconds");
		Assert.AreEqual (-648, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (-21474836480000, ts.Ticks, "Ticks");
	}

	[Test]
	public void NegativeTimeSpan () 
	{
		TimeSpan ts = new TimeSpan (-23, -59, -59);
		Assert.AreEqual (0, ts.Days, "Days");
		Assert.AreEqual (-23, ts.Hours, "Hours");
		Assert.AreEqual (-59, ts.Minutes, "Minutes");
		Assert.AreEqual (-59, ts.Seconds, "Seconds");
		Assert.AreEqual (0, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (-863990000000, ts.Ticks, "Ticks");
	}

	public void TestProperties ()
	{
		TimeSpan t1 = new TimeSpan (1,2,3,4,5);
		TimeSpan t2 = -t1;

		Assert.AreEqual (1, t1.Days, "A1");
		Assert.AreEqual (2, t1.Hours, "A2");
		Assert.AreEqual (3, t1.Minutes, "A3");
		Assert.AreEqual (4, t1.Seconds, "A4");
		Assert.AreEqual (5, t1.Milliseconds, "A5");
		Assert.AreEqual (-1, t2.Days, "A6");
		Assert.AreEqual (-2, t2.Hours, "A7");
		Assert.AreEqual (-3, t2.Minutes, "A8");
		Assert.AreEqual (-4, t2.Seconds, "A9");
		Assert.AreEqual (-5, t2.Milliseconds, "A10");
	}

	public void TestAdd ()
	{
		TimeSpan t1 = new TimeSpan (2,3,4,5,6);
		TimeSpan t2 = new TimeSpan (1,2,3,4,5);
		TimeSpan t3 = t1 + t2;
		TimeSpan t4 = t1.Add (t2);
		TimeSpan t5;
		bool exception;

		Assert.AreEqual (3, t3.Days, "A1");
		Assert.AreEqual (5, t3.Hours, "A2");
		Assert.AreEqual (7, t3.Minutes, "A3");
		Assert.AreEqual (9, t3.Seconds, "A4");
		Assert.AreEqual (11, t3.Milliseconds, "A5");
		Assert.AreEqual ("3.05:07:09.0110000", t4.ToString (), "A6");
		try
		{
			t5 = TimeSpan.MaxValue + new TimeSpan (1);			
			exception = false;
		}
		catch (OverflowException)
		{
			exception = true;
		}
		Assert.IsTrue (exception, "A7");
	}

	public void TestCompare ()
	{
		TimeSpan t1 = new TimeSpan (-1);
		TimeSpan t2 = new TimeSpan (1);
		int res;
		bool exception;

		Assert.AreEqual (-1, TimeSpan.Compare (t1, t2), "A1");
		Assert.AreEqual (1, TimeSpan.Compare (t2, t1), "A2");
		Assert.AreEqual (0, TimeSpan.Compare (t2, t2), "A3");
		Assert.AreEqual (-1, TimeSpan.Compare (TimeSpan.MinValue, TimeSpan.MaxValue), "A4");
		Assert.AreEqual (-1, t1.CompareTo (t2), "A5");
		Assert.AreEqual (1, t2.CompareTo (t1), "A6");
		Assert.AreEqual (0, t2.CompareTo (t2), "A7");
		Assert.AreEqual (-1, TimeSpan.Compare (TimeSpan.MinValue, TimeSpan.MaxValue), "A8");

		Assert.AreEqual (1, TimeSpan.Zero.CompareTo (null), "A9");
		
		try
		{
			res = TimeSpan.Zero.CompareTo("");
			exception = false;	
		}
		catch (ArgumentException)
		{
			exception = true;
		}
		Assert.IsTrue (exception, "A10");

		Assert.AreEqual (false, t1 == t2, "A11");
		Assert.AreEqual (false, t1 > t2, "A12");
		Assert.AreEqual (false, t1 >= t2, "A13");
		Assert.AreEqual (true, t1 != t2, "A14");
		Assert.AreEqual (true, t1 < t2, "A15");
		Assert.AreEqual (true, t1 <= t2, "A16");
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void NoNegateMinValue() {
		TimeSpan t1 = TimeSpan.MinValue.Negate ();
	}

	public void TestNegateAndDuration ()
	{
		TimeSpan t1;
		bool exception;

		Assert.AreEqual ("-00:00:00.0012345", new TimeSpan (12345).Negate ().ToString (), "A1");
		Assert.AreEqual ("00:00:00.0012345", new TimeSpan (-12345).Duration ().ToString (), "A2");
			
		try
		{
			t1 = TimeSpan.MinValue.Duration ();
			exception = false;
		}
		catch (OverflowException) {
			exception = true;
		}
		Assert.IsTrue (exception, "A4");

		Assert.AreEqual ("-00:00:00.0000077", (-(new TimeSpan (77))).ToString (), "A5");
		Assert.AreEqual ("00:00:00.0000077", (+(new TimeSpan(77))).ToString(), "A6");
	}

	public void TestEquals ()
	{
		TimeSpan t1 = new TimeSpan (1);
		TimeSpan t2 = new TimeSpan (2);
		string s = "justastring";

		Assert.AreEqual (true, t1.Equals (t1), "A1");
		Assert.AreEqual (false, t1.Equals (t2), "A2");
		Assert.AreEqual (false, t1.Equals (s), "A3");
		Assert.AreEqual (false, t1.Equals (null), "A4");
		Assert.AreEqual (true, TimeSpan.Equals (t1, t1), "A5");
		Assert.AreEqual (false, TimeSpan.Equals (t1, t2), "A6");
		Assert.AreEqual (false, TimeSpan.Equals (t1, null), "A7");
		Assert.AreEqual (false, TimeSpan.Equals (t1, s), "A8");
		Assert.AreEqual (false, TimeSpan.Equals (s, t2), "A9");
		Assert.AreEqual (true, TimeSpan.Equals (null, null), "A10");
	}

	public void TestFromXXXX ()
	{
		Assert.AreEqual ("12.08:16:48", TimeSpan.FromDays (12.345).ToString (), "A1");
		Assert.AreEqual ("12:20:42", TimeSpan.FromHours (12.345).ToString (), "A2");
		Assert.AreEqual ("00:12:20.7000000", TimeSpan.FromMinutes (12.345).ToString (), "A3");
		Assert.AreEqual ("00:00:12.3450000", TimeSpan.FromSeconds (12.345).ToString (), "A4");
		Assert.AreEqual ("00:00:00.0120000", TimeSpan.FromMilliseconds (12.345).ToString (), "A5");
		Assert.AreEqual ("00:00:00.0012345", TimeSpan.FromTicks (12345).ToString (), "A6");
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromDays_MinValue ()
	{
		TimeSpan.FromDays (Double.MinValue);
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromDays_MaxValue ()
	{
		TimeSpan.FromDays (Double.MaxValue);
	}

	[Test]
	[ExpectedException (typeof (ArgumentException))]
	public void FromDays_NaN ()
	{
		TimeSpan.FromDays (Double.NaN);
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromDays_PositiveInfinity ()
	{
		// LAMESPEC: Document to return TimeSpan.MaxValue
		Assert.AreEqual (TimeSpan.MaxValue, TimeSpan.FromDays (Double.PositiveInfinity));
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromDays_NegativeInfinity ()
	{
		// LAMESPEC: Document to return TimeSpan.MinValue
		Assert.AreEqual (TimeSpan.MinValue, TimeSpan.FromDays (Double.NegativeInfinity));
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromHours_MinValue ()
	{
		TimeSpan.FromHours (Double.MinValue);
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromHours_MaxValue ()
	{
		TimeSpan.FromHours (Double.MaxValue);
	}

	[Test]
	[ExpectedException (typeof (ArgumentException))]
	public void FromHours_NaN ()
	{
		TimeSpan.FromHours (Double.NaN);
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromHours_PositiveInfinity ()
	{
		// LAMESPEC: Document to return TimeSpan.MaxValue
		Assert.AreEqual (TimeSpan.MaxValue, TimeSpan.FromHours (Double.PositiveInfinity));
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromHours_NegativeInfinity ()
	{
		// LAMESPEC: Document to return TimeSpan.MinValue
		Assert.AreEqual (TimeSpan.MinValue, TimeSpan.FromHours (Double.NegativeInfinity));
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromMilliseconds_MinValue ()
	{
		TimeSpan.FromMilliseconds (Double.MinValue);
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromMilliseconds_MaxValue ()
	{
		TimeSpan.FromMilliseconds (Double.MaxValue);
	}

	[Test]
	[ExpectedException (typeof (ArgumentException))]
	public void FromMilliseconds_NaN ()
	{
		TimeSpan.FromMilliseconds (Double.NaN);
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromMilliseconds_PositiveInfinity ()
	{
		// LAMESPEC: Document to return TimeSpan.MaxValue
		Assert.AreEqual (TimeSpan.MaxValue, TimeSpan.FromMilliseconds (Double.PositiveInfinity));
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromMilliseconds_NegativeInfinity ()
	{
		// LAMESPEC: Document to return TimeSpan.MinValue
		Assert.AreEqual (TimeSpan.MinValue, TimeSpan.FromMilliseconds (Double.NegativeInfinity));
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromMinutes_MinValue ()
	{
		TimeSpan.FromMinutes (Double.MinValue);
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromMinutes_MaxValue ()
	{
		TimeSpan.FromMinutes (Double.MaxValue);
	}

	[Test]
	[ExpectedException (typeof (ArgumentException))]
	public void FromMinutes_NaN ()
	{
		TimeSpan.FromMinutes (Double.NaN);
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromMinutes_PositiveInfinity ()
	{
		// LAMESPEC: Document to return TimeSpan.MaxValue
		Assert.AreEqual (TimeSpan.MaxValue, TimeSpan.FromMinutes (Double.PositiveInfinity));
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromMinutes_NegativeInfinity ()
	{
		// LAMESPEC: Document to return TimeSpan.MinValue
		Assert.AreEqual (TimeSpan.MinValue, TimeSpan.FromMinutes (Double.NegativeInfinity));
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromSeconds_MinValue ()
	{
		TimeSpan.FromSeconds (Double.MinValue);
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromSeconds_MaxValue ()
	{
		TimeSpan.FromSeconds (Double.MaxValue);
	}

	[Test]
	[ExpectedException (typeof (ArgumentException))]
	public void FromSeconds_NaN ()
	{
		TimeSpan.FromSeconds (Double.NaN);
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromSeconds_PositiveInfinity ()
	{
		// LAMESPEC: Document to return TimeSpan.MaxValue
		Assert.AreEqual (TimeSpan.MaxValue, TimeSpan.FromSeconds (Double.PositiveInfinity));
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void FromSeconds_NegativeInfinity ()
	{
		// LAMESPEC: Document to return TimeSpan.MinValue
		Assert.AreEqual (TimeSpan.MinValue, TimeSpan.FromSeconds (Double.NegativeInfinity));
	}

	public void TestGetHashCode ()
	{
		Assert.AreEqual (77, new TimeSpan (77).GetHashCode (), "A1");
	}

	private void ParseHelper (string s, bool expectFormat, bool expectOverflow, string expect)
	{
		bool formatException = false;
		bool overflowException = false;
		string result = "junk ";

		try {
			result =  TimeSpan.Parse (s).ToString ();
		}
		catch (OverflowException) {
			overflowException = true;
		}
		catch (FormatException) {
			formatException = true;
		}
		Assert.AreEqual (expectFormat, formatException, "A1 [" + s + "]");
		Assert.AreEqual (expectOverflow, overflowException, "A2 " + s + "]");

		if (!expectOverflow && !expectFormat) {
			Assert.AreEqual (expect, result, "A3 [" + s + "]");
		}
	}

	[Test]
	public void TestParse ()
	{
		ParseHelper (" 13:45:15 ",false, false, "13:45:15");
		ParseHelper (" -1:2:3 ", false, false, "-01:02:03");

#if NET_4_0 || NET_2_1
		// In 4.0 when the first part is out of range, it parses it as day.
		ParseHelper (" 25:11:12 ", false, false, "25.11:12:00");
		ParseHelper (" 24:11:12 ", false, false, "24.11:12:00");
		ParseHelper (" 23:11:12 ", false, false, "23:11:12");
#else
		ParseHelper (" 25:0:0 ",false, true, "dontcare");
#endif

		ParseHelper ("-21.23:59:59.9999999", false, false, "-21.23:59:59.9999999");
		ParseHelper ("10:12  ", false, false, "10:12:00");
		ParseHelper ("aaa", true, false, "dontcare");

		ParseHelper ("100000000000000.1:1:1", false, true, "dontcare");
		ParseHelper ("24:60:60", false, true, "dontcare");
		ParseHelper ("0001:0002:0003.12     ", false, false, "01:02:03.1200000");

#if NET_4_0 || NET_2_1
		// In 4.0 when a section has more than 7 digits an OverflowException is thrown.
		ParseHelper (" 1:2:3:12345678 ", false, true, "dontcare");
#else
		ParseHelper (" 1:2:3:12345678 ", true, false, "dontcare"); 
#endif

#if NET_4_0	|| NET_2_1
		ParseHelper ("10:11:12:13", false, false, "10.11:12:13"); // Days using : instead of . as separator
		ParseHelper ("10.11", true, false, "dontcare"); // days+hours is invalid

		// Force the use of french culture -which is using a non common NumberDecimalSeparator-
		// as current culture, to show that the Parse method is *actually* being culture sensitive
		// *and* also keeping the compatibility with '.'
		CultureInfo french_culture = CultureInfo.GetCultureInfo ("fr-FR");
		CultureInfo prev_culture = CultureInfo.CurrentCulture;
		try {
			Thread.CurrentThread.CurrentCulture = french_culture;
			ParseHelper ("10:10:10,006", false, false, "10:10:10.0060000");
			ParseHelper ("10:10:10.006", false, false, "10:10:10.0060000");
		} finally {
			// restore culture
			Thread.CurrentThread.CurrentCulture = prev_culture;
		}
#endif

		ParseHelper ("00:00:00", false, false, "00:00:00");
		ParseHelper ("00:10:00", false, false, "00:10:00");
	}

	// LAMESPEC: timespan in documentation is wrong - hh:mm:ss isn't mandatory
	[Test]
	public void Parse_Days_WithoutColon () 
	{
		TimeSpan ts = TimeSpan.Parse ("1");
		Assert.AreEqual (1, ts.Days, "Days");
	}

	public void TestSubstract ()
	{
		TimeSpan t1 = new TimeSpan (2,3,4,5,6);
		TimeSpan t2 = new TimeSpan (1,2,3,4,5);
		TimeSpan t3 = t1 - t2;
		TimeSpan t4 = t1.Subtract (t2);
		TimeSpan t5;
		bool exception;

		Assert.AreEqual ("1.01:01:01.0010000", t3.ToString (), "A1");
		Assert.AreEqual ("1.01:01:01.0010000", t4.ToString (), "A2");
		try {
			t5 = TimeSpan.MinValue - new TimeSpan (1);
			exception = false;
		}
		catch (OverflowException) {
			exception = true;
		}
		Assert.IsTrue (exception, "A3");
	}

	public void TestToString () 
	{
		TimeSpan t1 = new TimeSpan (1,2,3,4,5);
		TimeSpan t2 = -t1;
		
		Assert.AreEqual ("1.02:03:04.0050000", t1.ToString (), "A1");
		Assert.AreEqual ("-1.02:03:04.0050000", t2.ToString (), "A2");
		Assert.AreEqual ("10675199.02:48:05.4775807", TimeSpan.MaxValue.ToString (), "A3");
		Assert.AreEqual ("-10675199.02:48:05.4775808", TimeSpan.MinValue.ToString (), "A4");
	}

	[Test]
	public void ToString_Constants () 
	{
		Assert.AreEqual ("00:00:00", TimeSpan.Zero.ToString (), "Zero");
		Assert.AreEqual ("10675199.02:48:05.4775807", TimeSpan.MaxValue.ToString (), "MaxValue");
		Assert.AreEqual ("-10675199.02:48:05.4775808", TimeSpan.MinValue.ToString (), "MinValue");
	}

	[Test]
	public void Parse_InvalidValuesAndFormat_ExceptionOrder () 
	{
		// hours should be between 0 and 23 but format is also invalid (too many dots)
		// In 2.0 overflow as precedence over format, but not in 4.0
#if NET_4_0 || NET_2_1
		try {
			TimeSpan.Parse ("0.99.99.0");
			Assert.Fail ("#A1");
		} catch (FormatException) {
		}
#else
		try {
			TimeSpan.Parse ("0.99.99.0");
			Assert.Fail ("#A1");
		} catch (OverflowException) {
		}
#endif
		try {
			TimeSpan.Parse ("0.999999999999.99.0");
			Assert.Fail ("#A2");
		} catch (OverflowException) {
		}
	}

	[Test]
	public void Parse_MinMaxValues () 
	{
		Assert.AreEqual (TimeSpan.MaxValue, TimeSpan.Parse ("10675199.02:48:05.4775807"), "MaxValue");
		Assert.AreEqual (TimeSpan.MinValue, TimeSpan.Parse ("-10675199.02:48:05.4775808"), "MinValue");
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void Parse_OverMaxValue() 
	{
		TimeSpan.Parse ("10675199.02:48:05.4775808");
	}

	[Test]
	[ExpectedException (typeof (OverflowException))]
	public void Parse_UnderMinValue() 
	{
		TimeSpan.Parse ("-10675199.02:48:05.4775809");
	}

	[Test]
	public void ParseMissingSeconds ()
	{
		// as seen in ML for http://resources.esri.com/arcgisserver/apis/silverlight/
		TimeSpan ts = TimeSpan.Parse ("0:0:.75");

		Assert.AreEqual (0, ts.Days, "Days");
		Assert.AreEqual (0, ts.Hours, "Hours");
		Assert.AreEqual (750, ts.Milliseconds, "Milliseconds");
		Assert.AreEqual (0, ts.Minutes, "Minutes");
		Assert.AreEqual (0, ts.Seconds, "Seconds");
		Assert.AreEqual (7500000, ts.Ticks, "Ticks");
		Assert.AreEqual (0.0000086805555555555555, ts.TotalDays, 0.00000000000000001, "TotalDays");
		Assert.AreEqual (0.00020833333333333332, ts.TotalHours, 0.00000000000000001, "TotalHours");
		Assert.AreEqual (750.0, ts.TotalMilliseconds, "TotalMilliseconds");
		Assert.AreEqual (0.0125, ts.TotalMinutes, "TotalMinutes");
		Assert.AreEqual (0.75, ts.TotalSeconds, "TotalSeconds");
	}

	// 'Ported' the Parse test to use TryParse
	[Test]
	public void TryParse ()
	{
		TimeSpan result;

		Assert.AreEqual (true, TimeSpan.TryParse (" 13:45:15 ", out result), "#A1");
		Assert.AreEqual ("13:45:15", result.ToString (), "#A2");

		Assert.AreEqual (true, TimeSpan.TryParse (" -1:2:3 ", out result), "#B1");
		Assert.AreEqual ("-01:02:03", result.ToString (), "#B2");

		Assert.AreEqual (false, TimeSpan.TryParse ("aaa", out result), "#C2");

		Assert.AreEqual (true, TimeSpan.TryParse ("-21.23:59:59.9999999", out result), "#D1");
		Assert.AreEqual ("-21.23:59:59.9999999", result.ToString (), "#D2");

		Assert.AreEqual (false, TimeSpan.TryParse ("100000000000000.1:1:1", out result), "#E1");
		Assert.AreEqual (false, TimeSpan.TryParse ("24:60:60", out result), "#E2");

#if NET_4_0
		Assert.AreEqual (true, TimeSpan.TryParse ("0001:0002:0003.12     ", out result), "#F1");
#else
		Assert.AreEqual (true, TimeSpan.TryParse ("0001:0002:0003.12     ", out result), "#F1");
		Assert.AreEqual ("01:02:03.1200000", result.ToString (), "#F2");
#endif

		Assert.AreEqual (false, TimeSpan.TryParse (" 1:2:3:12345678 ", out result), "#G1");

		// Min and Max values
		Assert.AreEqual (true, TimeSpan.TryParse ("10675199.02:48:05.4775807", out result), "MaxValue#1");
		Assert.AreEqual (TimeSpan.MaxValue, result, "MaxValue#2");
		Assert.AreEqual (true, TimeSpan.TryParse ("-10675199.02:48:05.4775808", out result), "MinValue#1");
		Assert.AreEqual (TimeSpan.MinValue, result, "MinValue#2");

#if NET_4_0
		// Force the use of french culture -which is using a non common NumberDecimalSeparator-
		// as current culture, to show that the Parse method is *actually* being culture sensitive
		CultureInfo french_culture = CultureInfo.GetCultureInfo ("fr-FR");
		CultureInfo prev_culture = CultureInfo.CurrentCulture;
		result = new TimeSpan (0, 10, 10, 10, 6);
		try {
			Thread.CurrentThread.CurrentCulture = french_culture;
			Assert.AreEqual (true, TimeSpan.TryParse ("10:10:10,006", out result), "#CultureSensitive1");
			Assert.AreEqual ("10:10:10.0060000", result.ToString (), "#CultureSensitive2");
		} finally {
			// restore culture
			Thread.CurrentThread.CurrentCulture = prev_culture;
		}
#endif
	}

	[Test]
	public void TryParseErrors ()
	{
		TimeSpan result;

		Assert.AreEqual (false, TimeSpan.TryParse ("0.99.99.0", out result), "Format#1");
		Assert.AreEqual (false, TimeSpan.TryParse ("10675199.02:48:05.4775808", out result), "OverMaxValue");
		Assert.AreEqual (false, TimeSpan.TryParse ("-10675199.02:48:05.4775809", out result), "UnderMinValue");
	}

#if NET_4_0
	[Test]
	public void TryParseOverloads ()
	{ 
		TimeSpan result;

		// We use fr-FR culture since its NumericDecimalSeparator is not the same used by
		// most cultures - including the invariant one.
		CultureInfo french_culture = CultureInfo.GetCultureInfo ("fr-FR");
		Assert.AreEqual (true, TimeSpan.TryParse ("11:50:50,006", french_culture, out result), "#A1");

		// LAMESPEC - msdn states that an instance of DateTimeFormatInfo is retrieved to
		// obtain culture sensitive information, but at least in the betas that's false
		DateTimeFormatInfo format_info = new DateTimeFormatInfo ();
		format_info.TimeSeparator = ";";
		Assert.AreEqual (false, TimeSpan.TryParse ("11;50;50", format_info, out result), "#B1");
		Assert.AreEqual (true, TimeSpan.TryParse ("11:50:50", format_info, out result), "#B2");
	}

	[Test]
	public void ParseExact ()
	{
		CultureInfo french_culture = CultureInfo.GetCultureInfo ("fr-FR");
		CultureInfo us_culture = CultureInfo.GetCultureInfo ("en-US");

		// At this point we are only missing the style bites and then we are
		// pretty much done with the standard formats.

		//
		// 'g' format - this is the short and culture sensitive format
		//
		string [] g_format = new string [] { "g" };
		ParseExactHelper ("12", g_format, false, false, "12.00:00:00");
		ParseExactHelper ("11:12", g_format, false, false, "11:12:00");
		ParseExactHelper ("-11:12", g_format, false, false, "-11:12:00");
		ParseExactHelper ("25:13", g_format, true, false, "dontcare");
		ParseExactHelper ("11:66", g_format, true, false, "dontcare"); // I'd have expected OverflowExc here
		ParseExactHelper ("11:12:13", g_format, false, false, "11:12:13");
		ParseExactHelper ("-11:12:13", g_format, false, false, "-11:12:13");
		ParseExactHelper ("10.11:12:13", g_format, true, false, "dontcare"); // this should work as well
		ParseExactHelper ("10.11:12:13", g_format, true, false, "dontcare", us_culture);
		ParseExactHelper ("10.11:12:13", g_format, true, false, "dontcare", CultureInfo.InvariantCulture);
		ParseExactHelper ("10:11:12:66", g_format, true, false, "dontcare");
		ParseExactHelper ("10:11:12:13", g_format, false, false, "10.11:12:13");
		ParseExactHelper ("11:12:13.6", g_format, false, false, "11:12:13.6000000", CultureInfo.InvariantCulture);
		ParseExactHelper ("11:12:13,6", g_format, false, false, "11:12:13.6000000", french_culture);
		ParseExactHelper ("10:11:12:13.6", g_format, false, false, "10.11:12:13.6000000", us_culture);
		ParseExactHelper (" 10:11:12:13.6 ", g_format, false, false, "10.11:12:13.6000000", us_culture);
		ParseExactHelper ("10:11", g_format, false, false, "10:11:00", null, TimeSpanStyles.None);
		ParseExactHelper ("10:11", g_format, false, false, "10:11:00", null, TimeSpanStyles.AssumeNegative); // no effect

		// 
		// G format
		//
		string [] G_format = new string [] { "G" };
		ParseExactHelper ("9:10:12", G_format, true, false, "dontcare");
		ParseExactHelper ("9:10:12.6", G_format, true, false, "dontcare");
		ParseExactHelper ("3.9:10:12", G_format, true, false, "dontcare");
		ParseExactHelper ("3.9:10:12.153", G_format, true, false, "dontcare"); // this should be valid...
		ParseExactHelper ("3:9:10:12.153", G_format, false, false, "3.09:10:12.1530000", us_culture);
		ParseExactHelper ("0:9:10:12.153", G_format, false, false, "09:10:12.1530000", us_culture);
		ParseExactHelper ("03:09:10:12.153", G_format, false, false, "3.09:10:12.1530000", us_culture);
		ParseExactHelper ("003:009:0010:0012.00153", G_format, false, false, "3.09:10:12.0015300", us_culture);
		ParseExactHelper ("3:9:10:66.153", G_format, true, false, "dontcare"); // seconds out of range
		ParseExactHelper ("3:9:10:12.153", G_format, true, false, "dontcare", french_culture); // fr-FR uses ',' as decimal separator
		ParseExactHelper ("3:9:10:12,153", G_format, false, false, "3.09:10:12.1530000", french_culture);
		ParseExactHelper ("  3:9:10:12.153  ", G_format, false, false, "3.09:10:12.1530000", us_culture);
		ParseExactHelper ("3:9:10:13.153", G_format, false, false, "3.09:10:13.1530000", us_culture, TimeSpanStyles.AssumeNegative);

		// c format
		string [] c_format = new string [] { "c" };
		ParseExactHelper ("12", c_format, false, false, "12.00:00:00");
		ParseExactHelper ("12:11", c_format, false, false, "12:11:00");
		ParseExactHelper ("12:66", c_format, true, false, "dontcare");
		ParseExactHelper ("10.11:12", c_format, false, false, "10.11:12:00");
		ParseExactHelper ("10.11:12:13", c_format, false, false, "10.11:12:13");
		ParseExactHelper ("10:11:12:13", c_format, true, false, "dontcare"); // this is normally accepted in the Parse method
		ParseExactHelper ("10.11:12:13.6", c_format, false, false, "10.11:12:13.6000000");
		ParseExactHelper ("10:11:12,6", c_format, true, false, "dontcare");
		ParseExactHelper ("10:11:12,6", c_format, true, false, "dontcare", french_culture);
		ParseExactHelper ("  10:11:12.6  ", c_format, false, false, "10:11:12.6000000");
		ParseExactHelper ("10:12", c_format, false, false, "10:12:00", null, TimeSpanStyles.AssumeNegative);
		ParseExactHelper ("10:123456789999", c_format, true, false, "dontcare");

		ParseExactHelper ("10:12", new string [0], true, false, "dontcare");
		ParseExactHelper ("10:12", new string [] { String.Empty }, true, false, "dontcare");
		ParseExactHelper ("10:12", new string [] { null }, true, false, "dontcare");
	}

	[Test]
	public void ParseExactMultipleFormats ()
	{
		ParseExactHelper ("10:12", new string [] { "G", "g" }, false, false, "10:12:00");
		ParseExactHelper ("10:12", new string [] { "g", "G" }, false, false, "10:12:00");
		ParseExactHelper ("7.8:9:10", new string [] { "G", "g" }, true, false, "dontcare");
		ParseExactHelper ("7.8:9:10", new string [] { "G", "g", "c" }, false, false, "7.08:09:10");
		ParseExactHelper ("7:8:9:10", new string [] { "c", "g" }, false, false, "7.08:09:10");
		ParseExactHelper ("7:8:9:10", new string [] { "c", "G" }, true, false, "dontcare");
		ParseExactHelper ("7.123456789:1", new string [] { "c", "G", "g" }, true, false, "dontcare");
		ParseExactHelper ("7.123456789:1", new string [] { "G", "g", "c" }, true, false, "dontcare");
		ParseExactHelper ("1234567890123456", new string [] { "c", "g" }, true, false, "dontcare"); // I'd expect an OverflowException
		ParseExactHelper ("10:12", new string [] { null, "c", "g" }, true, false, "10:12:00");
		ParseExactHelper ("10:12", new string [] { String.Empty, "c", "g" }, true, false, "10:12:00");
	}

	[Test]
	public void ParseExactCustomFormats ()
	{
		// Days
		ParseExactHelper ("33", new string [] { "%d" }, false, false, "33.00:00:00");
		ParseExactHelper ("00", new string [] { "%d" }, false, false, "00:00:00");
		ParseExactHelper ("33", new string [] { "%dd" }, false, false, "33.00:00:00");
		ParseExactHelper ("3333", new string [] { "%d" }, false, false, "3333.00:00:00");
		ParseExactHelper ("3333", new string [] { "%ddd" }, true, false, "3333.00:00:00"); // 'dd' mismatch the digit count
		ParseExactHelper ("3333", new string [] { "%dddd" }, false, false, "3333.00:00:00");
		ParseExactHelper ("00033", new string [] { "%ddddd" }, false, false, "33.00:00:00");
		ParseExactHelper ("00033", new string [] { "%d" }, false, false, "33.00:00:00");
		ParseExactHelper ("00000003", new string [] { "%dddddddd" }, false, false, "3.00:00:00"); // up to 8 'd'
		ParseExactHelper ("000000003", new string [] { "%ddddddddd" }, true, false, "dontcare");
		ParseExactHelper ("33", new string [] { "d" }, true, false, "33.00:00:00"); // This is sort of weird.
		ParseExactHelper ("33", new string [] { "dd" }, false, false, "33.00:00:00");
		ParseExactHelper ("-33", new string [] { "%d" }, true, false, "dontcare");
		ParseExactHelper ("33", new string [] { "%d" }, false, false, "-33.00:00:00", null, TimeSpanStyles.AssumeNegative);

		// Hours
		ParseExactHelper ("12", new string [] { "%h" }, false, false, "12:00:00");
		ParseExactHelper ("00", new string [] { "%h" }, false, false, "00:00:00");
		ParseExactHelper ("012", new string [] { "%h" }, true, false, "dontcare"); // more than 2 digits
		ParseExactHelper ("00012", new string [] { "%hhhhh" }, true, false, "dontcare");
		ParseExactHelper ("15", new string [] { "%h" }, false, false, "15:00:00");
		ParseExactHelper ("24", new string [] { "%h" }, true, false, "dontcare");
		ParseExactHelper ("15", new string [] { "%hh" }, false, false, "15:00:00");
		ParseExactHelper ("1", new string [] { "%hh" }, true, false, "dontcare"); // 'hh' but a single digit
		ParseExactHelper ("01", new string [] { "%hh" }, false, false, "01:00:00");
		ParseExactHelper ("015", new string [] { "%hhh" }, true, false, "dontcare"); // Too many 'h'
		ParseExactHelper ("12", new string [] { "h" }, true, false, "dontcare");
		ParseExactHelper ("12", new string [] { "hh" }, false, false, "12:00:00");
		ParseExactHelper ("-15", new string [] {"%h"}, true, false, "dontcare"); // Explicit - not accepted
		ParseExactHelper ("15", new string [] { "%h" }, false, false, "-15:00:00", null, TimeSpanStyles.AssumeNegative);
		ParseExactHelper ("15", new string [] { "%H" }, true, false, "dontcare"); // Uppercase is not accepted

		// Minutes
		ParseExactHelper ("12", new string [] { "%m" }, false, false, "00:12:00");
		ParseExactHelper ("00", new string [] { "%m" }, false, false, "00:00:00");
		ParseExactHelper ("60", new string [] { "%m" }, true, false, "dontcare");
		ParseExactHelper ("12", new string [] { "%mm" }, false, false, "00:12:00");
		ParseExactHelper ("1", new string [] { "%mm" }, true, false, "dontcare");
		ParseExactHelper ("12", new string [] { "%mmm" }, true, false, "dontcare");
		ParseExactHelper ("12", new string [] { "m" }, true, false, "dontcare");
		ParseExactHelper ("12", new string [] { "mm" }, false, false, "00:12:00");
		ParseExactHelper ("-12", new string [] { "%m" }, true, false, "dontcare");
		ParseExactHelper ("12", new string [] { "%m" }, false, false, "-00:12:00", null, TimeSpanStyles.AssumeNegative);
		ParseExactHelper ("12", new string [] { "%M" }, true, false, "dontcare");

		// Seconds
		ParseExactHelper ("12", new string [] { "%s" }, false, false, "00:00:12");
		ParseExactHelper ("00", new string [] { "%s" }, false, false, "00:00:00");
		ParseExactHelper ("000", new string [] { "%s" }, true, false, "dontcare");
		ParseExactHelper ("12", new string [] { "%ss" }, false, false, "00:00:12");
		ParseExactHelper ("12", new string [] { "%sss" }, true, false, "dontcare");
		ParseExactHelper ("60", new string [] { "%s" }, true, false, "dontcare");
		ParseExactHelper ("-12", new string [] { "%s" }, true, false, "dontcare");
		ParseExactHelper ("12", new string [] { "%s" }, false, false, "-00:00:12", null, TimeSpanStyles.AssumeNegative);

		// Fractions of seconds - f
		ParseExactHelper ("3", new string [] { "%f" }, false, false, "00:00:00.3000000");
		ParseExactHelper ("0", new string [] { "%f" }, false, false, "00:00:00");
		ParseExactHelper ("03", new string [] { "%f" }, true, false, "dontcare"); // This would work for other elements
		ParseExactHelper ("10", new string [] { "%f" }, true, false, "dontcare"); // Only a digit is accepted with '%f'
		ParseExactHelper ("3", new string [] { "%ff" }, true, false, "dontcare");
		ParseExactHelper ("12", new string [] { "%ff" }, false, false, "00:00:00.1200000");
		ParseExactHelper ("123", new string [] { "%ff" }, true, false, "dontcare");
		ParseExactHelper ("123", new string [] { "%fff" }, false, false, "00:00:00.1230000");
		ParseExactHelper ("1234", new string [] { "%ffff" }, false, false, "00:00:00.1234000");
		ParseExactHelper ("1234567", new string [] { "%fffffff" }, false, false, "00:00:00.1234567");
		ParseExactHelper ("1234567", new string [] { "%FfFFFFF" }, true, false, "dontcare"); // Mixed f and M
		ParseExactHelper ("12345678", new string [] { "%ffffffff" }, true, false, "dontcare");
		ParseExactHelper ("0000000", new string [] { "%fffffff" }, false, false, "00:00:00");

		// Fractions of second - F
		ParseExactHelper ("3", new string [] { "%F" }, false, false, "00:00:00.3000000");
		ParseExactHelper ("333", new string [] { "%FFFFF" }, false, false, "00:00:00.3330000");
		ParseExactHelper ("1234567", new string [] { "%FFFFFFF" }, false, false, "00:00:00.1234567");

		// Multiple symbols
		ParseExactHelper ("9:10", new string [] { @"h\:m" }, false, false, "09:10:00");
		ParseExactHelper ("9;10", new string [] { @"h\;m" }, false, false, "09:10:00");
		ParseExactHelper ("10:9", new string [] { @"m\:h" }, false, false, "09:10:00");
		ParseExactHelper ("10:9", new string [] { @"%m\:%h" }, false, false, "09:10:00");
		ParseExactHelper ("9 10", new string [] { @"h\ m" }, false, false, "09:10:00");
		ParseExactHelper ("9   10", new string [] { @"h\ \ \ m" }, false, false, "09:10:00");
		ParseExactHelper (" 9:10 ", new string [] { @"h\:m" }, true, false, "dontcare");
		ParseExactHelper ("9:10:11", new string [] { @"h\:m\:s" }, false, false, "09:10:11");
		ParseExactHelper ("9:10:11:6", new string [] { @"h\:m\:s\:f" }, false, false, "09:10:11.6000000");
		ParseExactHelper ("9:10:11:666", new string [] { @"h\:m\:s\:f" }, true, false, "dontcare"); // fff with 1 digit
		ParseExactHelper ("9:10:11:", new string [] { @"h\:m\:s\:F" }, false, false, "09:10:11"); // optional frac of seconds
		ParseExactHelper ("9:10:11:", new string [] { @"h\:m\:s\:FF" }, false, false, "09:10:11");
		ParseExactHelper ("9:10:11::", new string [] { @"h\:m\:s\:F\:" }, false, false, "09:10:11");
		ParseExactHelper ("8:9:10:11:6666666", new string [] { @"d\:h\:m\:s\:fffffff" }, false, false, "8.09:10:11.6666666");
		ParseExactHelper ("8:9:10:11:6666666", new string [] { @"d\:h\:m\:s\:fffffff" }, false, false, "-8.09:10:11.6666666", 
				null, TimeSpanStyles.AssumeNegative);
		ParseExactHelper ("9:10", new string [] { @"h\:h" }, true, false, "dontcare"); // Repeated element

		// Misc
		ParseExactHelper (" 0 ", new string [] { "%d" }, true, false, "dontcare");
		ParseExactHelper (" 0 ", new string [] { " %d " }, true, false, "dontcare");
		ParseExactHelper ("0", new string [] { " %d " }, true, false, "dontcare");
		ParseExactHelper ("::", new string [] { @"\:\:" }, false, false, "00:00:00"); // funny
		ParseExactHelper ("::", new string [] { @"\:\:" }, false, false, "00:00:00", null, TimeSpanStyles.AssumeNegative);
		ParseExactHelper (" 0", new string [] { @"\ d" }, false, false, "00:00:00");
		ParseExactHelper ("Interval = 12:13:14", new string [] { @"'Interval = 'h\:m\:s" }, false, false, "12:13:14");
	}

	void ParseExactHelper (string input, string [] formats, bool format_error, bool overflow_error, string expected, 
        IFormatProvider formatProvider = null, TimeSpanStyles timeSpanStyles = TimeSpanStyles.None)
	{
		bool overflow_exc = false;
		bool format_exc = false;
		TimeSpan result = TimeSpan.Zero;

		try {
			result = TimeSpan.ParseExact (input, formats, formatProvider, timeSpanStyles);
		} catch (OverflowException) {
			overflow_exc = true;
		} catch (FormatException) {
			format_exc = true;
		}

		Assert.AreEqual (format_error, format_exc, "A1");
		Assert.AreEqual (overflow_error, overflow_exc, "A2");
		if (!overflow_exc && !format_exc)
			Assert.AreEqual (expected, result.ToString ());
	}

	// 'Ported' the ParseExact test to use TryParseExact instead.
	[Test]
	public void TryParseExact ()
	{
		CultureInfo french_culture = CultureInfo.GetCultureInfo ("fr-FR");
		CultureInfo us_culture = CultureInfo.GetCultureInfo ("en-US");

		//
		// 'g' format - this is the short and culture sensitive format
		//
		string [] g_format = new string [] { "g" };
		TryParseExactHelper ("12", g_format, false, "12.00:00:00");
		TryParseExactHelper ("11:12", g_format, false, "11:12:00");
		TryParseExactHelper ("-11:12", g_format, false, "-11:12:00");
		TryParseExactHelper ("25:13", g_format, true, "dontcare");
		TryParseExactHelper ("11:66", g_format, true, "dontcare"); // I'd have expected OverflowExc here
		TryParseExactHelper ("11:12:13", g_format, false, "11:12:13");
		TryParseExactHelper ("-11:12:13", g_format, false, "-11:12:13");
		TryParseExactHelper ("10.11:12:13", g_format, true, "dontcare"); // this should work as well
		TryParseExactHelper ("10.11:12:13", g_format, true, "dontcare", us_culture);
		TryParseExactHelper ("10.11:12:13", g_format, true, "dontcare", CultureInfo.InvariantCulture);
		TryParseExactHelper ("10:11:12:66", g_format, true, "dontcare");
		TryParseExactHelper ("10:11:12:13", g_format, false, "10.11:12:13");
		TryParseExactHelper ("11:12:13.6", g_format, false, "11:12:13.6000000", CultureInfo.InvariantCulture);
		TryParseExactHelper ("11:12:13,6", g_format, false, "11:12:13.6000000", french_culture);
		TryParseExactHelper ("10:11:12:13.6", g_format, false, "10.11:12:13.6000000", us_culture);
		TryParseExactHelper (" 10:11:12:13.6 ", g_format, false, "10.11:12:13.6000000", us_culture);
		TryParseExactHelper ("10:11", g_format, false, "10:11:00", null, TimeSpanStyles.None);
		TryParseExactHelper ("10:11", g_format, false, "10:11:00", null, TimeSpanStyles.AssumeNegative); // no effect

		// 
		// G format
		//
		string [] G_format = new string [] { "G" };
		TryParseExactHelper ("9:10:12", G_format, true, "dontcare");
		TryParseExactHelper ("9:10:12.6", G_format, true, "dontcare");
		TryParseExactHelper ("3.9:10:12", G_format, true, "dontcare");
		TryParseExactHelper ("3.9:10:12.153", G_format, true, "dontcare"); // this should be valid...
		TryParseExactHelper ("3:9:10:12.153", G_format, false, "3.09:10:12.1530000", us_culture);
		TryParseExactHelper ("0:9:10:12.153", G_format, false, "09:10:12.1530000", us_culture);
		TryParseExactHelper ("03:09:10:12.153", G_format, false, "3.09:10:12.1530000", us_culture);
		TryParseExactHelper ("003:009:0010:0012.00153", G_format, false, "3.09:10:12.0015300", us_culture);
		TryParseExactHelper ("3:9:10:66.153", G_format, true, "dontcare"); // seconds out of range
		TryParseExactHelper ("3:9:10:12.153", G_format, true, "dontcare", french_culture); // fr-FR uses ',' as decimal separator
		TryParseExactHelper ("3:9:10:12,153", G_format, false, "3.09:10:12.1530000", french_culture);
		TryParseExactHelper ("  3:9:10:12.153  ", G_format, false, "3.09:10:12.1530000", us_culture);
		TryParseExactHelper ("3:9:10:13.153", G_format, false, "3.09:10:13.1530000", us_culture, TimeSpanStyles.AssumeNegative);

		// c format
		string [] c_format = new string [] { "c" };
		TryParseExactHelper ("12", c_format, false, "12.00:00:00");
		TryParseExactHelper ("12:11", c_format, false, "12:11:00");
		TryParseExactHelper ("12:66", c_format, true, "dontcare");
		TryParseExactHelper ("10.11:12", c_format, false, "10.11:12:00");
		TryParseExactHelper ("10.11:12:13", c_format, false, "10.11:12:13");
		TryParseExactHelper ("10:11:12:13", c_format, true, "dontcare"); // this is normally accepted in the Parse method
		TryParseExactHelper ("10.11:12:13.6", c_format, false, "10.11:12:13.6000000");
		TryParseExactHelper ("10:11:12,6", c_format, true, "dontcare");
		TryParseExactHelper ("10:11:12,6", c_format, true, "dontcare", french_culture);
		TryParseExactHelper ("  10:11:12.6  ", c_format, false, "10:11:12.6000000");
		TryParseExactHelper ("10:12", c_format, false, "10:12:00", null, TimeSpanStyles.AssumeNegative);
		TryParseExactHelper ("10:123456789999", c_format, true, "dontcare");

		TryParseExactHelper ("10:12", new string [0], true, "dontcare");
		TryParseExactHelper ("10:12", new string [] { String.Empty }, true, "dontcare");
		TryParseExactHelper ("10:12", new string [] { null }, true, "dontcare");
	}

	void TryParseExactHelper (string input, string [] formats, bool error, string expected, IFormatProvider formatProvider = null,
			TimeSpanStyles styles = TimeSpanStyles.None)
	{
		TimeSpan result;
		bool success;

		success = TimeSpan.TryParseExact (input, formats, formatProvider, styles, out result);
		Assert.AreEqual (!error, success);
		if (!error)
			Assert.AreEqual (expected, result.ToString ());
	}

	[Test]
	public void ParseExactExceptions ()
	{
		try {
			TimeSpan.ParseExact (null, "g", null);
			Assert.Fail ("#A1");
		} catch (ArgumentNullException) {
		}

		try {
			TimeSpan.ParseExact ("10:12", (string)null, null);
			Assert.Fail ("#A2");
		} catch (ArgumentNullException) {
		}

		try {
			TimeSpan.ParseExact ("10:12", (string [])null, null);
			Assert.Fail ("#A3");
		} catch (ArgumentNullException) {
		}
	}

	[Test]
	public void ToStringOverloads ()
	{
		TimeSpan ts = new TimeSpan (1, 2, 3, 4, 6);

		// Simple version - culture invariant
		Assert.AreEqual ("1.02:03:04.0060000", ts.ToString (), "#A1");
		Assert.AreEqual ("1.02:03:04.0060000", ts.ToString ("c"), "#A2");
		Assert.AreEqual ("1.02:03:04.0060000", ts.ToString (null), "#A3");
		Assert.AreEqual ("1.02:03:04.0060000", ts.ToString (String.Empty), "#A4");

		//
		// IFormatProvider ones - use a culture changing numeric format.
		// Also, we use fr-FR as culture, since it uses some elements different to invariant culture
		//
		CultureInfo culture = CultureInfo.GetCultureInfo ("fr-FR");

		Assert.AreEqual ("1:2:03:04,006", ts.ToString ("g", culture), "#B1");
		Assert.AreEqual ("1:02:03:04,0060000", ts.ToString ("G", culture), "#B2");
		Assert.AreEqual ("1.02:03:04.0060000", ts.ToString ("c", culture), "#B3"); // 'c' format ignores CultureInfo
		Assert.AreEqual ("1.02:03:04.0060000", ts.ToString ("t", culture), "#B4"); // 't' and 'T' are the same as 'c'
		Assert.AreEqual("1.02:03:04.0060000", ts.ToString("T", culture), "#B5");

		ts = new TimeSpan (4, 5, 6);
		Assert.AreEqual ("4:05:06", ts.ToString ("g", culture), "#C1");
		Assert.AreEqual ("0:04:05:06,0000000", ts.ToString ("G", culture), "#C2");
	}

	[Test]
	public void ToStringCustomFormats ()
	{
		TimeSpan ts = new TimeSpan (1, 3, 5, 7);

		Assert.AreEqual ("1", ts.ToString ("%d"), "#A0");
		Assert.AreEqual ("3", ts.ToString ("%h"), "#A1");
		Assert.AreEqual ("5", ts.ToString ("%m"), "#A2");
		Assert.AreEqual ("7", ts.ToString ("%s"), "#A3");
		Assert.AreEqual ("0", ts.ToString ("%f"), "#A4");
		Assert.AreEqual (String.Empty, ts.ToString ("%F"), "#A5"); // Nothing to display

		Assert.AreEqual ("01", ts.ToString ("dd"), "#B0");
		Assert.AreEqual ("00000001", ts.ToString ("dddddddd"), "#B1");
		Assert.AreEqual ("03", ts.ToString ("hh"), "#B2");
		Assert.AreEqual ("05", ts.ToString ("mm"), "#B3");
		Assert.AreEqual ("07", ts.ToString ("ss"), "#B4");
		Assert.AreEqual ("00", ts.ToString ("ff"), "#B5");
		Assert.AreEqual ("0000000", ts.ToString ("fffffff"), "#B6");
		Assert.AreEqual (String.Empty, ts.ToString ("FF"), "#B7");

		Assert.AreEqual ("01;03;05", ts.ToString (@"dd\;hh\;mm"), "#C0");
		Assert.AreEqual ("05 07", ts.ToString (@"mm\ ss"), "#C1");
		Assert.AreEqual ("05 07 ", ts.ToString (@"mm\ ss\ FF"), "#C2");
		Assert.AreEqual ("Result = 3 hours with 5 minutes and 7 seconds",
				ts.ToString (@"'Result = 'h' hours with 'm' minutes and 's' seconds'"), "#C3");
		Assert.AreEqual ("  ", ts.ToString (@"\ \ "), "#C4");

		ts = new TimeSpan (1, 3, 5, 7, 153);
		Assert.AreEqual ("1", ts.ToString ("%F"), "#D0");
		Assert.AreEqual ("15", ts.ToString ("FF"), "#D1"); // Don't use %, as the parser gets confused here
		Assert.AreEqual ("153", ts.ToString ("FFFFFFF"), "#D2");

		// Negative values are shown without sign
		ts = new TimeSpan (-1, -3, -5);
		Assert.AreEqual ("1", ts.ToString ("%h"), "#E0");
		Assert.AreEqual ("3", ts.ToString ("%m"), "#E1");
		Assert.AreEqual ("5", ts.ToString ("%s"), "#E2");
	}

	[Test]
	public void ToStringOverloadsErrors ()
	{
		TimeSpan ts = new TimeSpan (10, 10, 10);
		string result;

		try {
			result = ts.ToString ("non-valid");
			Assert.Fail ("#1");
		} catch (FormatException) {
		}

		try {
			result = ts.ToString ("C");
			Assert.Fail ("#2");
		} catch (FormatException) {
		}

		try
		{
			ts.ToString ("m");
			Assert.Fail ("#3");
		} catch (FormatException) {
		}

		try
		{
			ts.ToString ("d"); // Missing % for single char
			Assert.Fail ("#4");
		} catch (FormatException)
		{
		}

		try
		{
			ts.ToString ("ddddddddd");
			Assert.Fail ("#5");
		} catch (FormatException)
		{
		}

		try
		{
			ts.ToString ("hhh");
			Assert.Fail ("#5");
		} catch (FormatException)
		{
		}

		try
		{
			ts.ToString ("ffffffff");
			Assert.Fail ("6");
		} catch (FormatException)
		{
		}
	}
#endif
}

}