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.
32 using NUnit.Framework;
34 using System.Collections.Generic;
35 using System.Globalization;
38 namespace MonoTests.System.Globalization
41 public class EastAsianLunisolarCalendarTest
43 static ChineseLunisolarCalendar cn = new ChineseLunisolarCalendar ();
44 static JapaneseLunisolarCalendar jp = new JapaneseLunisolarCalendar ();
45 static TaiwanLunisolarCalendar tw = new TaiwanLunisolarCalendar ();
46 static KoreanLunisolarCalendar kr = new KoreanLunisolarCalendar ();
49 [Category ("NotWorking")]
50 public void ToDateTime ()
52 Assert.AreEqual (new DateTime (2000, 2, 5), cn.ToDateTime (2000, 1, 1, 0, 0, 0, 0), "cn1");
53 Assert.AreEqual (new DateTime (2000, 2, 5), jp.ToDateTime (12, 1, 1, 0, 0, 0, 0), "jp1"); // since 1988 (current epoch)
54 Assert.AreEqual (new DateTime (2000, 2, 5), tw.ToDateTime (89, 1, 1, 0, 0, 0, 0), "tw1"); // since 1912 (current epoch)
55 Assert.AreEqual (new DateTime (2000, 2, 5), kr.ToDateTime (2000, 1, 1, 0, 0, 0, 0), "kr1");
57 Assert.AreEqual (new DateTime (2001, 1, 24), cn.ToDateTime (2001, 1, 1, 0, 0, 0, 0), "cn2");
58 Assert.AreEqual (new DateTime (2001, 1, 24), jp.ToDateTime (13, 1, 1, 0, 0, 0, 0), "jp2");
59 Assert.AreEqual (new DateTime (2001, 1, 24), tw.ToDateTime (90, 1, 1, 0, 0, 0, 0), "tw2");
60 Assert.AreEqual (new DateTime (2001, 1, 24), kr.ToDateTime (2001, 1, 1, 0, 0, 0, 0), "kr2");
62 Assert.AreEqual (new DateTime (2002, 2, 12), cn.ToDateTime (2002, 1, 1, 0, 0, 0, 0), "cn3");
63 Assert.AreEqual (new DateTime (2002, 2, 12), jp.ToDateTime (14, 1, 1, 0, 0, 0, 0), "jp3");
64 Assert.AreEqual (new DateTime (2002, 2, 12), tw.ToDateTime (91, 1, 1, 0, 0, 0, 0), "tw3");
65 Assert.AreEqual (new DateTime (2002, 2, 12), kr.ToDateTime (2002, 1, 1, 0, 0, 0, 0), "kr3");
67 // actually it is 5th month which is leap, but that
68 // does not afffect on resulting DateTime
69 Assert.AreEqual (new DateTime (2001, 5, 23), cn.ToDateTime (2001, 5, 1, 0, 0, 0, 0), "cn4");
70 Assert.AreEqual (new DateTime (2001, 5, 23), jp.ToDateTime (13, 5, 1, 0, 0, 0, 0), "jp4");
71 Assert.AreEqual (new DateTime (2001, 5, 23), tw.ToDateTime (90, 5, 1, 0, 0, 0, 0), "tw4");
72 Assert.AreEqual (new DateTime (2001, 5, 23), kr.ToDateTime (2001, 5, 1, 0, 0, 0, 0), "kr4");
74 // here the leap month works.
75 Assert.AreEqual (new DateTime (2002, 2, 11), cn.ToDateTime (2001, 13, 30, 0, 0, 0, 0), "cn5");
76 Assert.AreEqual (new DateTime (2002, 2, 11), jp.ToDateTime (13, 13, 30, 0, 0, 0, 0), "jp5");
77 Assert.AreEqual (new DateTime (2002, 2, 11), tw.ToDateTime (90, 13, 30, 0, 0, 0, 0), "tw5");
78 Assert.AreEqual (new DateTime (2002, 2, 11), kr.ToDateTime (2001, 13, 30, 0, 0, 0, 0), "kr5");
80 Assert.AreEqual (cn.MinSupportedDateTime, cn.ToDateTime (1901, 1, 1, 0, 0, 0, 0), "cn6");
81 Assert.AreEqual (jp.MinSupportedDateTime, jp.ToDateTime (35, 1, 1, 0, 0, 0, 0, 3), "jp6"); // 1960-1-1
82 Assert.AreEqual (tw.MinSupportedDateTime, tw.ToDateTime (1, 1, 1, 0, 0, 0, 0), "tw6"); // 1912
83 Assert.AreEqual (kr.MinSupportedDateTime, kr.ToDateTime (918, 1, 1, 0, 0, 0, 0), "kr6");
85 Assert.AreEqual (jp.MinSupportedDateTime, cn.ToDateTime (1960, 1, 1, 0, 0, 0, 0), "jp-cn1");
89 [Category ("NotWorking")]
90 public void ToDateTimeOutOfRange ()
93 cn.ToDateTime (1900, 12, 29, 23, 59, 59, 0);
95 } catch (ArgumentOutOfRangeException) {
98 cn.ToDateTime (2000, 13, 29, 23, 59, 59, 0);
100 } catch (ArgumentOutOfRangeException) {
105 [Category ("NotWorking")]
106 public void GetYear ()
108 Assert.AreEqual (1901, cn.GetYear (new DateTime (1901, 2, 19, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#1");
109 Assert.AreEqual (1901, cn.GetYear (new DateTime (1902, 2, 07, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#2");
110 Assert.AreEqual (1902, cn.GetYear (new DateTime (1902, 2, 08, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#3");
111 Assert.AreEqual (1902, cn.GetYear (new DateTime (1903, 1, 28, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#4");
112 Assert.AreEqual (1903, cn.GetYear (new DateTime (1903, 1, 29, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#5");
113 // there was a leap month
114 Assert.AreEqual (1903, cn.GetYear (new DateTime (1904, 2, 15, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#6");
115 Assert.AreEqual (1904, cn.GetYear (new DateTime (1904, 2, 16, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#7");
119 [Category ("NotWorking")]
120 public void GetYear2 ()
122 Assert.AreEqual (1999, cn.GetYear (new DateTime (2000, 2, 4, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#1");
123 Assert.AreEqual (2000, cn.GetYear (new DateTime (2000, 2, 5, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#2");
124 Assert.AreEqual (11, jp.GetYear (new DateTime (2000, 2, 4, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#3");
125 Assert.AreEqual (12, jp.GetYear (new DateTime (2000, 2, 5, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#4");
126 Assert.AreEqual (88, tw.GetYear (new DateTime (2000, 2, 4, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#5");
127 Assert.AreEqual (89, tw.GetYear (new DateTime (2000, 2, 5, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#6");
128 Assert.AreEqual (1999, cn.GetYear (new DateTime (2000, 2, 4, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#7");
129 Assert.AreEqual (2000, cn.GetYear (new DateTime (2000, 2, 5, 0, 0, 0, DateTimeKind.Utc).ToLocalTime ()), "#8");
132 bool [] leapYears = new bool [] {
133 false, true, false, false, true,
134 false, true, false, false, true,
135 false, false, true, false, true,
136 false, false, true, false, // 19 years rotation
140 [Category ("NotWorking")]
141 public void IsLeapYear ()
143 //Assert.IsFalse (cn.IsLeapYear (1901), "#cn1901");
144 //Assert.AreEqual (0, cn.GetSexagenaryYear (cn.MinSupportedDateTime), "#60cn1");
146 for (int i = 0; i < 60; i++)
147 Assert.AreEqual (leapYears [i % 19], cn.IsLeapYear (2000 + i), "cn" + i);
148 for (int i = 0; i < 48; i++) // only 1-to-61 are allowed
149 Assert.AreEqual (leapYears [i % 19], jp.IsLeapYear (12 + i), "jp" + i);
150 for (int i = 0; i < 50; i++)
151 Assert.AreEqual (leapYears [i % 19], tw.IsLeapYear (89 + i), "tw" + i);
152 for (int i = 0; i < 50; i++)
153 Assert.AreEqual (leapYears [i % 19], kr.IsLeapYear (2000 + i), "kr" + i);
155 // 2033 Rain-Water jieqi (usui) new year day is in
157 Assert.IsTrue (cn.IsLeapYear (2033), "cn2033");
158 Assert.IsFalse (cn.IsLeapYear (2034), "cn2034");
162 [Category ("NotWorking")]
163 public void IsLeapMonth ()
165 Dictionary<int,int> d = new Dictionary<int,int> ();
175 d [2025] = 7; // hmm ...
177 d [2031] = 4; // hmmmm ...
178 d [2033] = 12; // hmmmmmm ...
180 for (int y = 2000; y < 2038; y++)
181 for (int m = 1; m <= 12; m++)
182 Assert.AreEqual (d.ContainsKey (y) && d [y] == m, cn.IsLeapMonth (y, m), "cn" + y + "/" + m);
184 d = new Dictionary<int,int> ();
199 for (int y = 89; y < 127; y++)
200 for (int m = 1; m <= 12; m++)
201 Assert.AreEqual (d.ContainsKey (y) && d [y] == m, tw.IsLeapMonth (y, m), "tw" + y + "/" + m);
203 d = new Dictionary<int,int> ();
211 for (int y = 12; y < 32; y++)
212 for (int m = 1; m <= 12; m++)
213 Assert.AreEqual (d.ContainsKey (y) && d [y] == m, jp.IsLeapMonth (y, m), "jp" + y + "/" + m);
215 d = new Dictionary<int,int> ();
223 for (int y = 2000; y < 2020; y++)
224 for (int m = 1; m <= 12; m++)
225 Assert.AreEqual (d.ContainsKey (y) && d [y] == m, kr.IsLeapMonth (y, m), "kr" + y + "/" + m);