1 // EastAsianLunisolarCalendarTest.cs
4 // Atsushi Enomoto <atsushi@ximian.com>
6 // Copyright (C) 2007 Novell, Inc. http://www.novell.com
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using NUnit.Framework;
33 using System.Collections.Generic;
34 using System.Globalization;
37 namespace MonoTests.System.Globalization
40 public class EastAsianLunisolarCalendarTest
42 static ChineseLunisolarCalendar cn = new ChineseLunisolarCalendar ();
43 static JapaneseLunisolarCalendar jp = new JapaneseLunisolarCalendar ();
44 static TaiwanLunisolarCalendar tw = new TaiwanLunisolarCalendar ();
45 static KoreanLunisolarCalendar kr = new KoreanLunisolarCalendar ();
48 [Category ("NotWorking")]
49 public void ToDateTime ()
51 Assert.AreEqual (new DateTime (2000, 2, 5), cn.ToDateTime (2000, 1, 1, 0, 0, 0, 0), "cn1");
52 Assert.AreEqual (new DateTime (2000, 2, 5), jp.ToDateTime (12, 1, 1, 0, 0, 0, 0), "jp1"); // since 1988 (current epoch)
53 Assert.AreEqual (new DateTime (2000, 2, 5), tw.ToDateTime (89, 1, 1, 0, 0, 0, 0), "tw1"); // since 1912 (current epoch)
54 Assert.AreEqual (new DateTime (2000, 2, 5), kr.ToDateTime (2000, 1, 1, 0, 0, 0, 0), "kr1");
56 Assert.AreEqual (new DateTime (2001, 1, 24), cn.ToDateTime (2001, 1, 1, 0, 0, 0, 0), "cn2");
57 Assert.AreEqual (new DateTime (2001, 1, 24), jp.ToDateTime (13, 1, 1, 0, 0, 0, 0), "jp2");
58 Assert.AreEqual (new DateTime (2001, 1, 24), tw.ToDateTime (90, 1, 1, 0, 0, 0, 0), "tw2");
59 Assert.AreEqual (new DateTime (2001, 1, 24), kr.ToDateTime (2001, 1, 1, 0, 0, 0, 0), "kr2");
61 Assert.AreEqual (new DateTime (2002, 2, 12), cn.ToDateTime (2002, 1, 1, 0, 0, 0, 0), "cn3");
62 Assert.AreEqual (new DateTime (2002, 2, 12), jp.ToDateTime (14, 1, 1, 0, 0, 0, 0), "jp3");
63 Assert.AreEqual (new DateTime (2002, 2, 12), tw.ToDateTime (91, 1, 1, 0, 0, 0, 0), "tw3");
64 Assert.AreEqual (new DateTime (2002, 2, 12), kr.ToDateTime (2002, 1, 1, 0, 0, 0, 0), "kr3");
66 // actually it is 5th month which is leap, but that
67 // does not afffect on resulting DateTime
68 Assert.AreEqual (new DateTime (2001, 5, 23), cn.ToDateTime (2001, 5, 1, 0, 0, 0, 0), "cn4");
69 Assert.AreEqual (new DateTime (2001, 5, 23), jp.ToDateTime (13, 5, 1, 0, 0, 0, 0), "jp4");
70 Assert.AreEqual (new DateTime (2001, 5, 23), tw.ToDateTime (90, 5, 1, 0, 0, 0, 0), "tw4");
71 Assert.AreEqual (new DateTime (2001, 5, 23), kr.ToDateTime (2001, 5, 1, 0, 0, 0, 0), "kr4");
73 // here the leap month works.
74 Assert.AreEqual (new DateTime (2002, 2, 11), cn.ToDateTime (2001, 13, 30, 0, 0, 0, 0), "cn5");
75 Assert.AreEqual (new DateTime (2002, 2, 11), jp.ToDateTime (13, 13, 30, 0, 0, 0, 0), "jp5");
76 Assert.AreEqual (new DateTime (2002, 2, 11), tw.ToDateTime (90, 13, 30, 0, 0, 0, 0), "tw5");
77 Assert.AreEqual (new DateTime (2002, 2, 11), kr.ToDateTime (2001, 13, 30, 0, 0, 0, 0), "kr5");
79 Assert.AreEqual (cn.MinSupportedDateTime, cn.ToDateTime (1901, 1, 1, 0, 0, 0, 0), "cn6");
80 Assert.AreEqual (jp.MinSupportedDateTime, jp.ToDateTime (35, 1, 1, 0, 0, 0, 0, 3), "jp6"); // 1960-1-1
81 Assert.AreEqual (tw.MinSupportedDateTime, tw.ToDateTime (1, 1, 1, 0, 0, 0, 0), "tw6"); // 1912
82 Assert.AreEqual (kr.MinSupportedDateTime, kr.ToDateTime (918, 1, 1, 0, 0, 0, 0), "kr6");
84 Assert.AreEqual (jp.MinSupportedDateTime, cn.ToDateTime (1960, 1, 1, 0, 0, 0, 0), "jp-cn1");
88 [Category ("NotWorking")]
89 public void ToDateTimeOutOfRange ()
92 cn.ToDateTime (1900, 12, 29, 23, 59, 59, 0);
94 } catch (ArgumentOutOfRangeException) {
97 cn.ToDateTime (2000, 13, 29, 23, 59, 59, 0);
99 } catch (ArgumentOutOfRangeException) {
104 [Category ("NotWorking")]
105 public void GetYear ()
107 Assert.AreEqual (1901, cn.GetYear (new DateTime (1901, 2, 19, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#1");
108 Assert.AreEqual (1901, cn.GetYear (new DateTime (1902, 2, 07, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#2");
109 Assert.AreEqual (1902, cn.GetYear (new DateTime (1902, 2, 08, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#3");
110 Assert.AreEqual (1902, cn.GetYear (new DateTime (1903, 1, 28, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#4");
111 Assert.AreEqual (1903, cn.GetYear (new DateTime (1903, 1, 29, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#5");
112 // there was a leap month
113 Assert.AreEqual (1903, cn.GetYear (new DateTime (1904, 2, 15, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#6");
114 Assert.AreEqual (1904, cn.GetYear (new DateTime (1904, 2, 16, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#7");
118 [Category ("NotWorking")]
119 public void GetYear2 ()
121 Assert.AreEqual (1999, cn.GetYear (new DateTime (2000, 2, 4, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#1");
122 Assert.AreEqual (2000, cn.GetYear (new DateTime (2000, 2, 5, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#2");
123 Assert.AreEqual (11, jp.GetYear (new DateTime (2000, 2, 4, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#3");
124 Assert.AreEqual (12, jp.GetYear (new DateTime (2000, 2, 5, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#4");
125 Assert.AreEqual (88, tw.GetYear (new DateTime (2000, 2, 4, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#5");
126 Assert.AreEqual (89, tw.GetYear (new DateTime (2000, 2, 5, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#6");
127 Assert.AreEqual (1999, cn.GetYear (new DateTime (2000, 2, 4, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#7");
128 Assert.AreEqual (2000, cn.GetYear (new DateTime (2000, 2, 5, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#8");
131 bool [] leapYears = new bool [] {
132 false, true, false, false, true,
133 false, true, false, false, true,
134 false, false, true, false, true,
135 false, false, true, false, // 19 years rotation
139 [Category ("NotWorking")]
140 public void IsLeapYear ()
142 //Assert.IsFalse (cn.IsLeapYear (1901), "#cn1901");
143 //Assert.AreEqual (0, cn.GetSexagenaryYear (cn.MinSupportedDateTime), "#60cn1");
145 for (int i = 0; i < 60; i++)
146 Assert.AreEqual (leapYears [i % 19], cn.IsLeapYear (2000 + i), "cn" + i);
147 for (int i = 0; i < 48; i++) // only 1-to-61 are allowed
148 Assert.AreEqual (leapYears [i % 19], jp.IsLeapYear (12 + i), "jp" + i);
149 for (int i = 0; i < 50; i++)
150 Assert.AreEqual (leapYears [i % 19], tw.IsLeapYear (89 + i), "tw" + i);
151 for (int i = 0; i < 50; i++)
152 Assert.AreEqual (leapYears [i % 19], kr.IsLeapYear (2000 + i), "kr" + i);
154 // 2033 Rain-Water jieqi (usui) new year day is in
156 Assert.IsTrue (cn.IsLeapYear (2033), "cn2033");
157 Assert.IsFalse (cn.IsLeapYear (2034), "cn2034");
161 [Category ("NotWorking")]
162 public void IsLeapMonth ()
164 Dictionary<int,int> d = new Dictionary<int,int> ();
174 d [2025] = 7; // hmm ...
176 d [2031] = 4; // hmmmm ...
177 d [2033] = 12; // hmmmmmm ...
179 for (int y = 2000; y < 2038; y++)
180 for (int m = 1; m <= 12; m++)
181 Assert.AreEqual (d.ContainsKey (y) && d [y] == m, cn.IsLeapMonth (y, m), "cn" + y + "/" + m);
183 d = new Dictionary<int,int> ();
198 for (int y = 89; y < 127; y++)
199 for (int m = 1; m <= 12; m++)
200 Assert.AreEqual (d.ContainsKey (y) && d [y] == m, tw.IsLeapMonth (y, m), "tw" + y + "/" + m);
202 d = new Dictionary<int,int> ();
210 for (int y = 12; y < 32; y++)
211 for (int m = 1; m <= 12; m++)
212 Assert.AreEqual (d.ContainsKey (y) && d [y] == m, jp.IsLeapMonth (y, m), "jp" + y + "/" + m);
214 d = new Dictionary<int,int> ();
222 for (int y = 2000; y < 2020; y++)
223 for (int m = 1; m <= 12; m++)
224 Assert.AreEqual (d.ContainsKey (y) && d [y] == m, kr.IsLeapMonth (y, m), "kr" + y + "/" + m);