[bcl]Add test for CultureInfo.DefaultThreadCurrentCulture
[mono.git] / mcs / class / corlib / Test / System.Globalization / CalendarTest.cs
1 // CalendarTest.cs
2 //
3 // (C) 2002 Ulrich Kunitz
4 //
5
6 using NUnit.Framework;
7 using System;
8 using System.Globalization;
9 using System.IO;
10
11 namespace MonoTests.System.Globalization
12 {
13
14 sealed class Date {
15         private int _day, _month, _year, _era;
16
17         public int Day {
18                 get {
19                         return _day;
20                 }
21                 set {
22                         if (value < 1 || value > 31)
23                                 throw new ArgumentOutOfRangeException(
24                                         "Day",
25                                         "Day must be between 1 and 31.");
26                         _day = value;
27                 }
28         }
29
30         public int Month {
31                 get {
32                         return _month;
33                 }
34                 set {
35                         if (value < 1 || value > 13)
36                                 throw new ArgumentOutOfRangeException(
37                                         "Month",
38                                         "Month must be between 1 and 13.");
39                         _month = value;
40                 }
41         }
42
43         public int Year {
44                 get {
45                         return _year;
46                 }
47                 set {
48                         _year = value;
49                 }
50         }
51
52         public int Era {
53                 get {
54                         return _era;
55                 }
56                 set {
57                         if (value < 1 || value > 10)
58                                 throw new ArgumentOutOfRangeException(
59                                         "Era",
60                                         "Era must be between 1 and 10.");
61                         _era = value;
62                 }
63         }
64                                         
65         public Date(int day, int month, int year, int era) {
66                 Day = day;
67                 Month = month;
68                 Year = year;
69                 Era = era;
70         }
71         public Date(int day, int month, int year) : this(day,month,year,1) {}
72         public Date() : this(1,1,1,1) {}
73
74         public DateTime ToDateTime(Calendar cal) {
75                 return cal.ToDateTime(Year,Month,Day,0,0,0,0,Era);
76         }
77
78         public void FromDateTime(Calendar cal, DateTime time) {
79                 Date dmy = new Date();
80                 dmy.Day = cal.GetDayOfMonth(time);
81                 dmy.Month = cal.GetMonth(time);
82                 dmy.Year = cal.GetYear(time);
83                 dmy.Era = cal.GetEra(time);
84                 Day = dmy.Day;
85                 Month = dmy.Month;
86                 Year = dmy.Year;
87                 Era = dmy.Era;
88         }
89
90         public override string ToString() {
91                 StringWriter sw = new StringWriter();
92                 sw.Write("{0}.{1}.{2}", Day, Month, Year);
93                 if (Era != 1) {
94                         sw.Write(" era {0}", Era);
95                 }
96                 return sw.ToString();
97         }
98
99         public override bool Equals(Object b) {
100                 if (b == null || GetType() != b.GetType())
101                         return false;
102                 return Equals(this, (Date)b);
103         }
104
105         public static bool Equals(Date a, Date b) {
106                 if (a == b)
107                         return true;
108                 if (a.Year != b.Year)
109                         return false;
110                 if (a.Month != b.Month)
111                         return false;
112                 if (a.Day != b.Day)
113                         return false;
114                 if (a.Era != b.Era)
115                         return false;
116                 return true;
117         }
118
119         public override int GetHashCode() {
120                 return ToString().GetHashCode();
121         }
122 } // class Date
123
124 [TestFixture]
125 public class CalendarTest {
126         private Calendar[] acal;
127         private GregorianCalendar gcal;
128         private JulianCalendar jucal;
129         private HijriCalendar hical;
130         private HebrewCalendar hecal;
131         private JapaneseCalendar jacal;
132         private TaiwanCalendar tacal;
133         private KoreanCalendar kcal;
134         private ThaiBuddhistCalendar tbcal;
135 #if NET_2_0
136         private ChineseLunisolarCalendar clcal;
137         private TaiwanLunisolarCalendar tlcal;
138         private JapaneseLunisolarCalendar jlcal;
139         private KoreanLunisolarCalendar klcal;
140 #endif
141
142         [SetUp]
143         protected void SetUp() {
144                 gcal = new GregorianCalendar();
145                 jucal = new JulianCalendar();
146                 hical = new HijriCalendar();
147                 hecal = new HebrewCalendar();
148                 jacal = new JapaneseCalendar();
149                 tacal = new TaiwanCalendar();
150                 kcal = new KoreanCalendar();
151                 tbcal = new ThaiBuddhistCalendar();
152                 acal = new Calendar[] {
153                         gcal, jucal, hical, hecal, jacal,
154                         tacal, kcal, tbcal};
155 #if NET_2_0
156                 clcal = new ChineseLunisolarCalendar ();
157                 tlcal = new TaiwanLunisolarCalendar ();
158                 jlcal = new JapaneseLunisolarCalendar ();
159                 klcal = new KoreanLunisolarCalendar ();
160 #endif
161         }
162
163         private void RowCheck(params Date[] adate) {
164                 if (adate.Length != acal.Length)
165                         throw new ArgumentException(
166                                 "Number of Date arguments doesn't match " +
167                                 "length of calendar array.");
168
169                 DateTime timeG = adate[0].ToDateTime(gcal);
170                 for (int i = 0; i < acal.Length; i++) {
171                         Date date = adate[i];
172                         if (date == null)
173                                 continue;
174                         Calendar cal = acal[i];
175
176                         DateTime time = date.ToDateTime(cal);
177                         StringWriter sw = new StringWriter();
178                         sw.Write("Calendar {0} computes wrong DateTime.",
179                                 cal);
180                         Assert.AreEqual(timeG, time, sw.ToString());
181
182                         sw = new StringWriter();
183                         Date ndate = new Date();
184                         ndate.FromDateTime(cal, time);
185                         sw.Write("Calendar {0} computes wrong date", cal);
186                         Assert.AreEqual(date, ndate, sw.ToString());
187                 }
188         }
189
190         // We are testing the implementation against the reference dates in
191         // Calendrical Calcualation. Please note that the CLR uses another
192         // epoch for the HijriCalendar, which might be the perfect thing
193         // to do.
194         [Test]
195         public void TestCCTable() {
196                 // Gr Ju Hi He Ja Ta Ko TB
197                 RowCheck(new Date(24,9,70,1),
198                         new Date(26,9,70,1),
199                         null,
200                         null,
201                         null,
202                         null,
203                         new Date(24,9,2403,1),
204                         new Date(24,9,613,1));
205                 RowCheck(new Date(2,10,135,1),
206                         new Date(3,10,135,1),
207                         null,
208                         null,
209                         null,
210                         null,
211                         new Date(2,10,2468,1),
212                         new Date(2,10,678,1));
213                 RowCheck(new Date(8,1,470,1),
214                         new Date(7,1,470,1),
215                         null,
216                         null,
217                         null,
218                         null,
219                         new Date(8,1,2803,1),
220                         new Date(8,1,1013,1));
221                 RowCheck(new Date(20,5,576,1),
222                         new Date(18,5,576,1),
223                         null,
224                         null,
225                         null,
226                         null,
227                         new Date(20,5,2909,1),
228                         new Date(20,5,1119,1));
229                 RowCheck(new Date(10,11,694,1),
230                         new Date(7,11,694,1),
231                         new Date(14,7,75,1),
232                         null,
233                         null,
234                         null,
235                         new Date(10,11,3027,1),
236                         new Date(10,11,1237,1));
237                 RowCheck(new Date(25,4,1013,1),
238                         new Date(19,4,1013,1),
239                         new Date(6,10,403,1),
240                         null,
241                         null,
242                         null,
243                         new Date(25,4,3346,1),
244                         new Date(25,4,1556,1));
245                 RowCheck(new Date(24,5,1096,1),
246                         new Date(18,5,1096,1),
247                         new Date(23,5,489,1),
248                         null,
249                         null,
250                         null,
251                         new Date(24,5,3429,1),
252                         new Date(24,5,1639,1));
253                 RowCheck(new Date(23,3,1190,1),
254                         new Date(16,3,1190,1),
255                         new Date(8,2,586,1),
256                         null,
257                         null,
258                         null,
259                         new Date(23,3,3523,1),
260                         new Date(23,3,1733,1));
261                 RowCheck(new Date(10,3,1240,1),
262                         new Date(3,3,1240,1),
263                         new Date(8,8,637,1),
264                         null,
265                         null,
266                         null,
267                         new Date(10,3,3573,1),
268                         new Date(10,3,1783,1));
269                 RowCheck(new Date(2,4,1288,1),
270                         new Date(26,3,1288,1),
271                         new Date(21,2,687,1),
272                         null,
273                         null,
274                         null,
275                         new Date(2,4,3621,1),
276                         new Date(2,4,1831,1));
277                 RowCheck(new Date(27,4,1298,1),
278                         new Date(20,4,1298,1),
279                         new Date(8,7,697,1),
280                         null,
281                         null,
282                         null,
283                         new Date(27,4,3631,1),
284                         new Date(27,4,1841,1));
285                 RowCheck(new Date(12,6,1391,1),
286                         new Date(4,6,1391,1),
287                         new Date(2,7,793,1),
288                         null,
289                         null,
290                         null,
291                         new Date(12,6,3724,1),
292                         new Date(12,6,1934,1));
293                 RowCheck(new Date(3,2,1436,1),
294                         new Date(25,1,1436,1),
295                         new Date(7,7,839,1),
296                         null,
297                         null,
298                         null,
299                         new Date(3,2,3769,1),
300                         new Date(3,2,1979,1));
301                 RowCheck(new Date(9,4,1492,1),
302                         new Date(31,3,1492,1),
303                         new Date(2,6,897,1),
304                         null,
305                         null,
306                         null,
307                         new Date(9,4,3825,1),
308                         new Date(9,4,2035,1));
309                 RowCheck(new Date(19,9,1553,1),
310                         new Date(9,9,1553,1),
311                         new Date(1,10,960,1),
312                         null,
313                         null,
314                         null,
315                         new Date(19,9,3886,1),
316                         new Date(19,9,2096,1));
317                 RowCheck(new Date(5,3,1560,1),
318                         new Date(24,2,1560,1),
319                         new Date(28,5,967,1),
320                         null,
321                         null,
322                         null,
323                         new Date(5,3,3893,1),
324                         new Date(5,3,2103,1));
325                 RowCheck(new Date(10,6,1648,1),
326                         new Date(31,5,1648,1),
327                         new Date(19,5,1058,1),
328                         new Date(20,9,5408,1),
329                         null,
330                         null,
331                         new Date(10,6,3981,1),
332                         new Date(10,6,2191,1));
333                 RowCheck(new Date(30,6,1680,1),
334                         new Date(20,6,1680,1),
335                         new Date(3,6,1091,1),
336                         new Date(3,11,5440,1),
337                         null,
338                         null,
339                         new Date(30,6,4013,1),
340                         new Date(30,6,2223,1));
341                 RowCheck(new Date(24,7,1716,1),
342                         new Date(13,7,1716,1),
343                         new Date(5,8,1128,1),
344                         new Date(5,11,5476,1),
345                         null,
346                         null,
347                         new Date(24,7,4049,1),
348                         new Date(24,7,2259,1));
349                 RowCheck(new Date(19,6,1768,1),
350                         new Date(8,6,1768,1),
351                         new Date(4,2,1182,1),
352                         new Date(4,10,5528,1),
353                         null,
354                         null,
355                         new Date(19,6,4101,1),
356                         new Date(19,6,2311,1));
357                 RowCheck(new Date(2,8,1819,1),
358                         new Date(21,7,1819,1),
359                         new Date(11,10,1234,1),
360                         new Date(11,11,5579,1),
361                         null,
362                         null,
363                         new Date(2,8,4152,1),
364                         new Date(2,8,2362,1));
365                 RowCheck(new Date(27,3,1839,1),
366                         new Date(15,3,1839,1),
367                         new Date(12,1,1255,1),
368                         new Date(12,7,5599,1),
369                         null,
370                         null,
371                         new Date(27,3,4172,1),
372                         new Date(27,3,2382,1));
373                 RowCheck(new Date(19,4,1903,1),
374                         new Date(6,4,1903,1),
375                         new Date(22,1,1321,1),
376                         new Date(22,7,5663,1),
377                         new Date(19,4,36,1),
378                         null,
379                         new Date(19,4,4236,1),
380                         new Date(19,4,2446,1));
381                 RowCheck(new Date(25,8,1929,1),
382                         new Date(12,8,1929,1),
383                         new Date(20,3,1348,1),
384                         new Date(19,12,5689,1),
385                         new Date(25,8,4,3),
386                         new Date(25,8,18,1),
387                         new Date(25,8,4262,1),
388                         new Date(25,8,2472,1));
389                 RowCheck(new Date(29,9,1941,1),
390                         new Date(16,9,1941,1),
391                         new Date(9,9,1360,1),
392                         new Date(8,1,5702,1),
393                         new Date(29,9,16,3),
394                         new Date(29,9,30,1),
395                         new Date(29,9,4274,1),
396                         new Date(29,9,2484,1));
397                 RowCheck(new Date(19,4,1943,1),
398                         new Date(6,4,1943,1),
399                         new Date(14,4,1362,1),
400                         new Date(14,8,5703,1),
401                         new Date(19,4,18,3),
402                         new Date(19,4,32,1),
403                         new Date(19,4,4276,1),
404                         new Date(19,4,2486,1));
405                 RowCheck(new Date(7,10,1943,1),
406                         new Date(24,9,1943,1),
407                         new Date(8,10,1362,1),
408                         new Date(8,1,5704,1),
409                         new Date(7,10,18,3),
410                         new Date(7,10,32,1),
411                         new Date(7,10,4276,1),
412                         new Date(7,10,2486,1));
413                 RowCheck(new Date(17,3,1992,1),
414                         new Date(4,3,1992,1),
415                         new Date(14,9,1412,1),
416                         new Date(12,7,5752,1),
417                         new Date(17,3,4,4),
418                         new Date(17,3,81,1),
419                         new Date(17,3,4325,1),
420                         new Date(17,3,2535,1));
421                 RowCheck(new Date(25,5,1996,1),
422                         new Date(12,5,1996,1),
423                         new Date(8,1,1417,1),
424                         new Date(7,9,5756,1),
425                         new Date(25,5,8,4),
426                         new Date(25,5,85,1),
427                         new Date(25,5,4329,1),
428                         new Date(25,5,2539,1));
429                 RowCheck(new Date(10,11,2038,1),
430                         new Date(28,10,2038,1),
431                         new Date(13,10,1460,1),
432                         new Date(12,2,5799,1),
433                         new Date(10,11,50,4),
434                         new Date(10,11,127,1),
435                         new Date(10,11,4371,1),
436                         new Date(10,11,2581,1));
437                 RowCheck(new Date(18,7,2094,1),
438                         new Date(5,7,2094,1),
439                         new Date(6,3,1518,1),
440                         new Date(5,11,5854,1),
441                         new Date(18,7,106,4),
442                         new Date(18,7,183,1),
443                         new Date(18,7,4427,1),
444                         new Date(18,7,2637,1));
445         }
446
447         [Test]
448         public void TestCalendarType() {
449                 GregorianCalendar gc = new GregorianCalendar(
450                         GregorianCalendarTypes.Arabic);
451                 Assert.AreEqual(GregorianCalendarTypes.Arabic,
452                                                 gc.CalendarType,
453                                                 "A01 Gregorian ctor with GregorianCalendarTypes parameter");
454                 gc.CalendarType = GregorianCalendarTypes.MiddleEastFrench;
455                 Assert.AreEqual(GregorianCalendarTypes.MiddleEastFrench, 
456                                          gc.CalendarType, 
457                                          "A02 GregorianCalendar.CalendarType");
458                         
459         }
460
461         [Test]
462         public void TestStandardEras() {
463                 Assert.AreEqual(1, GregorianCalendar.ADEra, "B01 ADEra");
464                 Assert.AreEqual(1, HebrewCalendar.HebrewEra, "B02 HebrewEra");
465                 Assert.AreEqual(1, HijriCalendar.HijriEra, "B03 HjriEra");
466                 Assert.AreEqual(1, JulianCalendar.JulianEra, "B04 JulianEra");
467                 Assert.AreEqual(1, KoreanCalendar.KoreanEra, "B05 KoreanEra");
468                 Assert.AreEqual(1, ThaiBuddhistCalendar.ThaiBuddhistEra, "B06 ThaiBuddhistEra");
469                         
470 #if NET_2_0
471                 Assert.AreEqual(1, ChineseLunisolarCalendar.ChineseEra, "CNLunisor");
472                 Assert.AreEqual(1, JapaneseLunisolarCalendar.JapaneseEra, "JPLunisor");
473                 Assert.AreEqual(1, KoreanLunisolarCalendar.GregorianEra, "KRLunisor");
474 #endif
475         }
476
477         [Test]
478         public void TestCurrentEra() {
479                 Assert.AreEqual(0, GregorianCalendar.CurrentEra, 
480                                          "C01 GregorianCalendar.CurrentEra");
481                 Assert.AreEqual(0, HebrewCalendar.CurrentEra,
482                                          "C02 HebrewCalendar.CurrentEra");
483                 Assert.AreEqual(0, HijriCalendar.CurrentEra, 
484                                          "C03 HijriCalendar.CurrentEra");
485                 Assert.AreEqual(0, JapaneseCalendar.CurrentEra, 
486                                          "C04 JapaneseCalendar.CurrentEra");
487                 Assert.AreEqual(0, JulianCalendar.CurrentEra, 
488                                          "C05 JulianCalendar.CurrentEra");
489                 Assert.AreEqual(0, KoreanCalendar.CurrentEra,
490                                          "C06 KoreanCalendar.CurrentEra");
491                 Assert.AreEqual(0, TaiwanCalendar.CurrentEra,
492                                          "C07 TaiwanCalendar.CurrentEra");
493                 Assert.AreEqual(0, ThaiBuddhistCalendar.CurrentEra,
494                                          "C08 ThaiBuddhistCalendar.CurrentEra");
495         }
496
497         [Test]
498         public void TestErasProperty() {
499                 foreach (Calendar cal in acal) {
500                         int check = 1;
501                         if (cal is JapaneseCalendar)
502                                 check = 4;
503                         Assert.AreEqual(check, cal.Eras.Length,
504                                                  String.Format("D01 {0}.Eras.Length", cal));
505                         cal.Eras[0] = 29;
506                         Assert.IsTrue(cal.Eras[0] != 29, String.Format("D02 {0}.Eras readonly", cal));
507                 }
508         }
509
510 #if NET_2_0
511         [Category ("NotWorking")]
512         [Test]
513         public void TestErasProperty2() {
514                 Assert.AreEqual(1, clcal.Eras.Length, "cn");
515                 Assert.AreEqual(1, tlcal.Eras.Length, "tw");
516                 Assert.AreEqual(2, jlcal.Eras.Length, "jp");
517                 Assert.AreEqual(1, klcal.Eras.Length, "kr");
518
519                 Assert.AreEqual(4, jlcal.Eras [0], "jp.1");
520                 Assert.AreEqual(3, jlcal.Eras [1], "jp.2");
521         }
522 #endif
523
524         [Test]
525         public void TestTwoDigitYearMax() {
526                 Assert.AreEqual(2029, gcal.TwoDigitYearMax,
527                                          "E01 TwoDigitYearMax GregorianCalendar");
528                 Assert.AreEqual(5790, hecal.TwoDigitYearMax,
529                                          "E02 TwoDigitYearMax HebrewCalendar");
530                 Assert.AreEqual(1451, hical.TwoDigitYearMax,
531                                          "E03 TwoDigitYearMax HijriCalendar");
532                 Assert.AreEqual(99, jacal.TwoDigitYearMax,
533                                          "E04 TwoDigitYearMax JapaneseCalendar");
534                 Assert.AreEqual(2029, jucal.TwoDigitYearMax,
535                                          "E05 TwoDigitYearMax JulianCalendar");
536                 Assert.AreEqual(4362, kcal.TwoDigitYearMax,
537                                          "E06 TwoDigitYearMax KoreanCalendar");
538                 Assert.AreEqual(99, tacal.TwoDigitYearMax,
539                                          "E07 TwoDigitYearMax TaiwanCalendar");
540                 Assert.AreEqual(2572, tbcal.TwoDigitYearMax,
541                                          "E08 TwoDigitYearMax ThaiBuddhistCalendar");
542                 foreach (Calendar cal in acal) {
543                         bool exception = false;
544                         try { 
545                                 cal.TwoDigitYearMax = 99;
546                         }
547                         catch (ArgumentOutOfRangeException) {
548                                 exception = true;
549                         }
550                         Assert.IsTrue(exception,
551                                    String.Format("E09 {0}.TwoDigitYearMax 99 " +
552                                                                  " out of range exception", cal));
553
554                         exception = false;
555                         int m = 10000;
556                         try {
557                                 m = cal.GetYear(DateTime.MaxValue)+1;
558                                 cal.TwoDigitYearMax = m;
559                         }
560                         catch (ArgumentException) {
561                                 exception = true;
562                         }
563                         Assert.IsTrue(exception,
564                                    String.Format("E10 {0}.TwoDigitYearMax out " +
565                                                                  " of range exception value {1}",
566                                                                  cal, m));
567                 }
568         }
569
570         [Test] // wrt bug #76252.
571         public void HebrewCalendarGetDaysInMonth ()
572         {
573                 HebrewCalendar c = new HebrewCalendar ();
574                 int year = c.GetYear (new DateTime (2005, 9, 1));
575                 Assert.AreEqual (5765, year);
576                 int days = c.GetDaysInMonth (year, 13, 1);
577                 Assert.AreEqual (29, days);
578         }
579
580         [Test] // bug #81783
581         public void GregorianAddMonth ()
582         {
583                 GregorianCalendar c = new GregorianCalendar ();
584                 DateTime d = new DateTime (2007, 5, 31);
585                 DateTime prev = c.AddMonths (d, -1);
586                 Assert.AreEqual (4, prev.Month, "prev");
587                 DateTime next = c.AddMonths (d, 1);
588                 Assert.AreEqual (6, next.Month, "next");
589
590                 d = new DateTime (2003, 12, 5);
591                 prev = c.AddMonths (d, -13);
592                 Assert.AreEqual (new DateTime (2002, 11, 5), prev, "prev2");
593                 next = c.AddMonths (d, 6);
594                 Assert.AreEqual (new DateTime (2004, 6, 5), next, "next2");
595         }
596
597         [Test]
598         public void AddYearOnLeapYear ()
599         {
600                 GregorianCalendar c = new GregorianCalendar ();
601                 DateTime d = new DateTime (2004, 2, 29);
602                 DateTime prev = c.AddYears (d, -1);
603                 Assert.AreEqual (2, prev.Month, "prev");
604                 DateTime next = c.AddYears (d, 1);
605                 Assert.AreEqual (2, next.Month, "next");
606         }
607
608 #if NET_2_0
609         [Test]
610         [Category ("NotWorking")]
611         public void GetLeapMonth ()
612         {
613                 GregorianCalendar gc = new GregorianCalendar ();
614                 Assert.AreEqual (0, gc.GetLeapMonth (2007), "#1-1");
615                 Assert.AreEqual (0, gc.GetLeapMonth (2008), "#1-2");
616                 Assert.AreEqual (0, gc.GetLeapMonth (2100), "#1-3");
617                 Assert.AreEqual (0, gc.GetLeapMonth (2000), "#1-4");
618
619                 JulianCalendar jc = new JulianCalendar ();
620                 Assert.AreEqual (0, jc.GetLeapMonth (2007), "#2-1");
621                 Assert.AreEqual (0, jc.GetLeapMonth (2008), "#2-2");
622                 Assert.AreEqual (0, jc.GetLeapMonth (2100), "#2-3");
623                 Assert.AreEqual (0, jc.GetLeapMonth (2000), "#2-4");
624                 Assert.AreEqual (0, jc.GetLeapMonth (2009), "#2-5");
625                 Assert.AreEqual (0, jc.GetLeapMonth (2010), "#2-6");
626
627                 HebrewCalendar hc = new HebrewCalendar ();
628                 // 3rd, 6th, 8th, 11th 14th and 17th year in every 19 are leap.
629                 // 5339 % 19 = 0.
630                 Assert.AreEqual (0, hc.GetLeapMonth (5343), "#3-1");
631                 Assert.AreEqual (0, hc.GetLeapMonth (5344), "#3-2");
632                 Assert.AreEqual (7, hc.GetLeapMonth (5345), "#3-3");
633                 Assert.AreEqual (0, hc.GetLeapMonth (5346), "#3-4");
634                 Assert.AreEqual (7, hc.GetLeapMonth (5347), "#3-5");
635                 Assert.AreEqual (0, hc.GetLeapMonth (5348), "#3-6");
636                 Assert.AreEqual (0, hc.GetLeapMonth (5349), "#3-7");
637
638                 ThaiBuddhistCalendar tc = new ThaiBuddhistCalendar ();
639                 Assert.AreEqual (0, tc.GetLeapMonth (2520), "#4-1");
640                 Assert.AreEqual (0, tc.GetLeapMonth (2521), "#4-2");
641                 Assert.AreEqual (0, tc.GetLeapMonth (2522), "#4-3");
642                 Assert.AreEqual (0, tc.GetLeapMonth (2523), "#4-4");
643
644                 ChineseLunisolarCalendar cc = new ChineseLunisolarCalendar ();
645                 Assert.AreEqual (0, cc.GetLeapMonth (2000), "#5-1");
646                 Assert.AreEqual (5, cc.GetLeapMonth (2001), "#5-2");
647                 Assert.AreEqual (0, cc.GetLeapMonth (2002), "#5-3");
648                 Assert.AreEqual (0, cc.GetLeapMonth (2003), "#5-4");
649                 Assert.AreEqual (3, cc.GetLeapMonth (2004), "#5-5");
650                 Assert.AreEqual (0, cc.GetLeapMonth (2005), "#5-6");
651                 Assert.AreEqual (8, cc.GetLeapMonth (2006), "#5-7");
652                 Assert.AreEqual (0, cc.GetLeapMonth (2007), "#5-8");
653                 Assert.AreEqual (0, cc.GetLeapMonth (2008), "#5-9");
654                 Assert.AreEqual (6, cc.GetLeapMonth (2009), "#5-10");
655                 Assert.AreEqual (0, cc.GetLeapMonth (2010), "#5-11");
656                 Assert.AreEqual (0, cc.GetLeapMonth (2011), "#5-12");
657                 Assert.AreEqual (5, cc.GetLeapMonth (2012), "#5-13");
658                 Assert.AreEqual (0, cc.GetLeapMonth (2013), "#5-14");
659                 Assert.AreEqual (10, cc.GetLeapMonth (2014), "#5-15");
660                 Assert.AreEqual (0, cc.GetLeapMonth (2015), "#5-16");
661                 Assert.AreEqual (0, cc.GetLeapMonth (2016), "#5-17");
662                 Assert.AreEqual (7, cc.GetLeapMonth (2017), "#5-18");
663                 Assert.AreEqual (0, cc.GetLeapMonth (2018), "#5-19");
664                 Assert.AreEqual (0, cc.GetLeapMonth (2019), "#5-20");
665
666                 KoreanLunisolarCalendar kc = new KoreanLunisolarCalendar ();
667                 Assert.AreEqual (0, kc.GetLeapMonth (2000), "#6-1");
668                 Assert.AreEqual (5, kc.GetLeapMonth (2001), "#6-2");
669                 Assert.AreEqual (0, kc.GetLeapMonth (2002), "#6-3");
670                 Assert.AreEqual (0, kc.GetLeapMonth (2003), "#6-4");
671                 Assert.AreEqual (3, kc.GetLeapMonth (2004), "#6-5");
672                 Assert.AreEqual (0, kc.GetLeapMonth (2005), "#6-6");
673                 Assert.AreEqual (8, kc.GetLeapMonth (2006), "#6-7");
674                 Assert.AreEqual (0, kc.GetLeapMonth (2007), "#6-8");
675                 Assert.AreEqual (0, kc.GetLeapMonth (2008), "#6-9");
676                 Assert.AreEqual (6, kc.GetLeapMonth (2009), "#6-10");
677                 Assert.AreEqual (0, kc.GetLeapMonth (2010), "#6-11");
678                 Assert.AreEqual (0, kc.GetLeapMonth (2011), "#6-12");
679                 Assert.AreEqual (4, kc.GetLeapMonth (2012)); // off from cn by 1, "#6-13");
680                 Assert.AreEqual (0, kc.GetLeapMonth (2013), "#6-14");
681                 Assert.AreEqual (10, kc.GetLeapMonth (2014), "#6-15");
682                 Assert.AreEqual (0, kc.GetLeapMonth (2015), "#6-16");
683                 Assert.AreEqual (0, kc.GetLeapMonth (2016), "#6-17");
684                 Assert.AreEqual (6, kc.GetLeapMonth (2017)); // off from cn by 1, "#6-18");
685                 Assert.AreEqual (0, kc.GetLeapMonth (2018), "#6-19");
686                 Assert.AreEqual (0, kc.GetLeapMonth (2019), "#6-20");
687         }
688
689         [Test]
690         public void GetWeekOfYear ()
691         {
692                 GregorianCalendar gc = new GregorianCalendar ();
693                 Assert.AreEqual (1, gc.GetWeekOfYear (new DateTime (2007, 1, 1), CalendarWeekRule.FirstDay, DayOfWeek.Sunday), "#1");
694                 //Assert.AreEqual (1, gc.GetWeekOfYear (new DateTime (2000, 1, 1), CalendarWeekRule.FirstDay, DayOfWeek.Sunday), "#2");
695                 Assert.AreEqual (3, gc.GetWeekOfYear (new DateTime (2000, 1, 10), CalendarWeekRule.FirstDay, DayOfWeek.Sunday), "#2");
696                 Assert.AreEqual (2, gc.GetWeekOfYear (new DateTime (2000, 1, 10), CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Sunday), "#3");
697                 Assert.AreEqual (2, gc.GetWeekOfYear (new DateTime (2000, 1, 10), CalendarWeekRule.FirstFullWeek, DayOfWeek.Sunday), "#4");
698                 Assert.AreEqual (52, gc.GetWeekOfYear (new DateTime (2000, 1, 1), CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Sunday), "#5");
699                 Assert.AreEqual (52, gc.GetWeekOfYear (new DateTime (2000, 1, 1), CalendarWeekRule.FirstFullWeek, DayOfWeek.Sunday), "#6");
700         }
701 #endif
702
703         [Test]
704         public void TestToFourDigitYear() {
705                 foreach (Calendar cal in acal) {
706                         bool working = true;
707                         int mod = 2000;
708                         if (cal is HebrewCalendar)
709                                 mod = 5500; 
710                         if (cal is KoreanCalendar)
711                                 mod = 3000;
712                         if (cal is JapaneseCalendar)
713                                 working = false;
714                         if (cal is TaiwanCalendar)
715                                 working = false;
716                         cal.TwoDigitYearMax = mod + 229;
717                         Assert.AreEqual(mod+229 , cal.TwoDigitYearMax,
718                                                  String.Format("F01 {0}.TwoDigitYearMax", cal));
719                         Assert.AreEqual(working ? mod+229 : 29,
720                                                  cal.ToFourDigitYear(29),
721                                                  String.Format("F02 {0}.ToFourDigitYear(29)",cal));
722                         Assert.AreEqual(
723                                 working ? mod+130 : 30,
724                                 cal.ToFourDigitYear(30),
725                                 String.Format("F03 {0}.ToFourDigitYear(30)",
726                                                           cal));
727                         Assert.AreEqual(mod, cal.ToFourDigitYear(mod),
728                                 String.Format("F04 {0}.ToFourDigitYear({1})",
729                                                           cal, mod));
730
731                         bool exception = false;
732                         try {
733                                 cal.ToFourDigitYear(-1);
734                         }
735                         catch (ArgumentOutOfRangeException) {
736                                 exception = true;
737                         }
738                         Assert.IsTrue(exception, String.Format(
739                                 "F05 {0}.ToFourDigitYear(-1) exception",
740                                 cal));
741                         exception = false;
742                         try {
743                                 cal.ToFourDigitYear(15000);
744                         }
745                         catch (ArgumentOutOfRangeException) {
746                                 exception = true;
747                         }
748                         Assert.IsTrue(exception, String.Format(
749                                 "F05 {0}.ToFourDigitYear(15000) exception",
750                                 cal));
751                 }
752         }
753
754         [Test]
755         public void TestToFourDigitYear2 ()
756         {
757                 GregorianCalendar gc = new GregorianCalendar ();
758                 Assert.AreEqual (2029, gc.ToFourDigitYear (29), "#1-1");
759                 Assert.AreEqual (1930, gc.ToFourDigitYear (30), "#1-2");
760                 Assert.AreEqual (2029, gc.ToFourDigitYear (2029), "#1-3");
761                 Assert.AreEqual (2030, gc.ToFourDigitYear (2030), "#1-4");
762
763                 HebrewCalendar hbc = new HebrewCalendar ();
764                 Assert.AreEqual (5790, hbc.ToFourDigitYear (90), "#2-1");
765                 Assert.AreEqual (5691, hbc.ToFourDigitYear (91), "#2-2");
766                 Assert.AreEqual (5790, hbc.ToFourDigitYear (5790), "#2-3");
767                 Assert.AreEqual (5691, hbc.ToFourDigitYear (5691), "#2-4");
768                 Assert.AreEqual (5999, hbc.ToFourDigitYear (5999), "#2-5");
769                 // LAMESPEC: .NET fails to throw an exception unlike documented
770                 /*
771                 try {
772                         hbc.ToFourDigitYear (6000);
773                         Assert.Fail ("#2-6");
774                 } catch (ArgumentOutOfRangeException) {
775                 }
776                 */
777
778                 ThaiBuddhistCalendar tc = new ThaiBuddhistCalendar ();
779                 Assert.AreEqual (2572, tc.ToFourDigitYear (72), "#3-1");
780                 Assert.AreEqual (2473, tc.ToFourDigitYear (73), "#3-2");
781                 Assert.AreEqual (2572, tc.ToFourDigitYear (2572), "#3-3");
782                 Assert.AreEqual (2573, tc.ToFourDigitYear (2573), "#3-4");
783                 Assert.AreEqual (9999, tc.ToFourDigitYear (9999), "#3-5");
784                 // LAMESPEC: .NET fails to throw an exception unlike documented
785                 /*
786                 try {
787                         tc.ToFourDigitYear (10000);
788                         Assert.Fail ("#3-6");
789                 } catch (ArgumentOutOfRangeException) {
790                 }
791                 */
792
793                 KoreanCalendar kc = new KoreanCalendar ();
794                 Assert.AreEqual (4362, kc.ToFourDigitYear (62), "#4-1");
795                 Assert.AreEqual (4263, kc.ToFourDigitYear (63), "#4-2");
796                 Assert.AreEqual (4362, kc.ToFourDigitYear (4362), "#4-3");
797                 Assert.AreEqual (4363, kc.ToFourDigitYear (4363), "#4-4");
798         }
799
800         // TODO: more tests :-)
801 } // class CalendarTest
802         
803 } // namespace MonoTests.System.Globalization