]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/main/tests/core/src/com/ibm/icu/dev/test/calendar/HebrewTest.java
go
[Dictionary.git] / jars / icu4j-4_4_2-src / main / tests / core / src / com / ibm / icu / dev / test / calendar / HebrewTest.java
1 /*\r
2  *******************************************************************************\r
3  * Copyright (C) 1996-2009, International Business Machines Corporation and    *\r
4  * others. All Rights Reserved.                                                *\r
5  *******************************************************************************\r
6  */\r
7 \r
8 package com.ibm.icu.dev.test.calendar;\r
9 import java.util.Date;\r
10 import java.util.Locale;\r
11 import java.util.MissingResourceException;\r
12 \r
13 import com.ibm.icu.impl.LocaleUtility;\r
14 import com.ibm.icu.text.DateFormat;\r
15 import com.ibm.icu.util.Calendar;\r
16 import com.ibm.icu.util.HebrewCalendar;\r
17 import com.ibm.icu.util.TimeZone;\r
18 import com.ibm.icu.util.ULocale;\r
19 \r
20 /**\r
21  * Tests for the <code>HebrewCalendar</code> class.\r
22  */\r
23 public class HebrewTest extends CalendarTest {\r
24     public static void main(String args[]) throws Exception {\r
25         new HebrewTest().run(args);\r
26     }\r
27 \r
28     // Constants to save typing.\r
29     public static final int TISHRI  = HebrewCalendar.TISHRI;\r
30     public static final int HESHVAN = HebrewCalendar.HESHVAN;\r
31     public static final int KISLEV  = HebrewCalendar.KISLEV;\r
32     public static final int TEVET   = HebrewCalendar.TEVET;\r
33     public static final int SHEVAT  = HebrewCalendar.SHEVAT;\r
34     public static final int ADAR_1  = HebrewCalendar.ADAR_1;\r
35     public static final int ADAR    = HebrewCalendar.ADAR;\r
36     public static final int NISAN   = HebrewCalendar.NISAN;\r
37     public static final int IYAR    = HebrewCalendar.IYAR;\r
38     public static final int SIVAN   = HebrewCalendar.SIVAN;\r
39     public static final int TAMUZ   = HebrewCalendar.TAMUZ;\r
40     public static final int AV      = HebrewCalendar.AV;\r
41     public static final int ELUL    = HebrewCalendar.ELUL;\r
42 \r
43     /**\r
44      * Test the behavior of HebrewCalendar.roll\r
45      * The only real nastiness with roll is the MONTH field, since a year can\r
46      * have a variable number of months.\r
47      */\r
48     public void TestRoll() {\r
49         int[][] tests = new int[][] {\r
50             //       input                roll by          output\r
51             //  year  month     day     field amount    year  month     day\r
52     \r
53             {   5759, HESHVAN,   2,     MONTH,   1,     5759, KISLEV,    2 },   // non-leap years\r
54             {   5759, SHEVAT,    2,     MONTH,   1,     5759, ADAR,      2 },\r
55             {   5759, SHEVAT,    2,     MONTH,   2,     5759, NISAN,     2 },\r
56             {   5759, SHEVAT,    2,     MONTH,  12,     5759, SHEVAT,    2 },\r
57             {   5759, AV,        1,     MONTH,  12,     5759, AV,        1 }, // Alan\r
58 \r
59             {   5757, HESHVAN,   2,     MONTH,   1,     5757, KISLEV,    2 },   // leap years\r
60             {   5757, SHEVAT,    2,     MONTH,   1,     5757, ADAR_1,    2 },\r
61             {   5757, SHEVAT,    2,     MONTH,   2,     5757, ADAR,      2 },\r
62             {   5757, SHEVAT,    2,     MONTH,   3,     5757, NISAN,     2 },\r
63             {   5757, SHEVAT,    2,     MONTH,  12,     5757, TEVET,     2 },\r
64             {   5757, SHEVAT,    2,     MONTH,  13,     5757, SHEVAT,    2 },\r
65             {   5757, AV,        1,     MONTH,  12,     5757, TAMUZ,     1 }, // Alan\r
66             \r
67             {   5757, KISLEV,    1,     DATE,   30,     5757, KISLEV,    2 },   // 29-day month\r
68             {   5758, KISLEV,    1,     DATE,   31,     5758, KISLEV,    2 },   // 30-day month\r
69             \r
70             // Try some other fields too\r
71             {   5757, TISHRI,    1,     YEAR,    1,     5758, TISHRI,    1 },\r
72    \r
73 \r
74             // Try some rolls that require other fields to be adjusted\r
75             {   5757, TISHRI,   30,     MONTH,   1,     5757, HESHVAN,  29 },\r
76             {   5758, KISLEV,   30,     YEAR,   -1,     5757, KISLEV,   29 },\r
77         };\r
78 //        try{\r
79             HebrewCalendar cal = new HebrewCalendar(UTC, Locale.getDefault());\r
80     \r
81             doRollAdd(ROLL, cal, tests);\r
82  //       }catch(MissingResourceException ex){\r
83 //            warnln("Got Exception: "+ ex.getMessage());\r
84  //       }\r
85     }\r
86     \r
87     /**\r
88      * Test the behavior of HebrewCalendar.roll\r
89      * The only real nastiness with roll is the MONTH field, since a year can\r
90      * have a variable number of months.\r
91      */\r
92     public void TestAdd() {\r
93         int[][] tests = new int[][] {\r
94             //       input                add by          output\r
95             //  year  month     day     field amount    year  month     day\r
96             {   5759, HESHVAN,   2,     MONTH,   1,     5759, KISLEV,    2 },   // non-leap years\r
97             {   5759, SHEVAT,    2,     MONTH,   1,     5759, ADAR,      2 },\r
98             {   5759, SHEVAT,    2,     MONTH,   2,     5759, NISAN,     2 },\r
99             {   5759, SHEVAT,    2,     MONTH,  12,     5760, SHEVAT,    2 },\r
100 \r
101             {   5757, HESHVAN,   2,     MONTH,   1,     5757, KISLEV,    2 },   // leap years\r
102             {   5757, SHEVAT,    2,     MONTH,   1,     5757, ADAR_1,    2 },\r
103             {   5757, SHEVAT,    2,     MONTH,   2,     5757, ADAR,      2 },\r
104             {   5757, SHEVAT,    2,     MONTH,   3,     5757, NISAN,     2 },\r
105             {   5757, SHEVAT,    2,     MONTH,  12,     5758, TEVET,     2 },\r
106             {   5757, SHEVAT,    2,     MONTH,  13,     5758, SHEVAT,    2 },\r
107             \r
108             {   5762, AV,        1,     MONTH,   1,     5762, ELUL,      1 },   // JB#2327\r
109             {   5762, AV,       30,     DATE,    1,     5762, ELUL,      1 },   // JB#2327\r
110             {   5762, ELUL,      1,     DATE,   -1,     5762, AV,       30 },   // JB#2327\r
111             {   5762, ELUL,      1,     MONTH,  -1,     5762, AV,        1 },   // JB#2327\r
112             \r
113             {   5757, KISLEV,    1,     DATE,   30,     5757, TEVET,     2 },   // 29-day month\r
114             {   5758, KISLEV,    1,     DATE,   31,     5758, TEVET,     2 },   // 30-day month\r
115         };\r
116         try{\r
117             HebrewCalendar cal = new HebrewCalendar(UTC, Locale.getDefault());\r
118     \r
119             doRollAdd(ADD, cal, tests);\r
120         }catch( MissingResourceException ex){\r
121             warnln("Could not load the locale data");\r
122         }\r
123     }\r
124 \r
125     /**\r
126      * A huge list of test cases to make sure that computeTime and computeFields\r
127      * work properly for a wide range of data.\r
128      */\r
129     public void TestCases() {\r
130         try{\r
131             final TestCase[] testCases = {\r
132                     //\r
133                     // Most of these test cases were taken from the back of\r
134                     // "Calendrical Calculations", with some extras added to help\r
135                     // debug a few of the problems that cropped up in development.\r
136                     //\r
137                     // The months in this table are 1-based rather than 0-based,\r
138                     // because it's easier to edit that way.\r
139                     //\r
140                     //         Julian Day  Era  Year  Month Day  WkDay Hour Min Sec\r
141                     new TestCase(1507231.5,  0,  3174,   12,  10,  SUN,   0,  0,  0),\r
142                     new TestCase(1660037.5,  0,  3593,    3,  25,  WED,   0,  0,  0),\r
143                     new TestCase(1746893.5,  0,  3831,    1,   3,  WED,   0,  0,  0),\r
144                     new TestCase(1770641.5,  0,  3896,    1,   9,  SUN,   0,  0,  0),\r
145                     new TestCase(1892731.5,  0,  4230,    4,  18,  WED,   0,  0,  0),\r
146                     new TestCase(1931579.5,  0,  4336,   10,   4,  MON,   0,  0,  0),\r
147                     new TestCase(1974851.5,  0,  4455,    2,  13,  SAT,   0,  0,  0),\r
148                     new TestCase(2091164.5,  0,  4773,    9,   6,  SUN,   0,  0,  0),\r
149                     new TestCase(2121509.5,  0,  4856,    9,  23,  SUN,   0,  0,  0),\r
150                     new TestCase(2155779.5,  0,  4950,    8,   7,  FRI,   0,  0,  0),\r
151                     new TestCase(2174029.5,  0,  5000,    7,   8,  SAT,   0,  0,  0),\r
152                     new TestCase(2191584.5,  0,  5048,    8,  21,  FRI,   0,  0,  0),\r
153                     new TestCase(2195261.5,  0,  5058,    9,   7,  SUN,   0,  0,  0),\r
154                     new TestCase(2229274.5,  0,  5151,   11,   1,  SUN,   0,  0,  0),\r
155                     new TestCase(2245580.5,  0,  5196,    5,   7,  WED,   0,  0,  0),\r
156                     new TestCase(2266100.5,  0,  5252,    8,   3,  SAT,   0,  0,  0),\r
157                     new TestCase(2288542.5,  0,  5314,    1,   1,  SAT,   0,  0,  0),\r
158                     new TestCase(2290901.5,  0,  5320,    6,  27,  SAT,   0,  0,  0),\r
159                     new TestCase(2323140.5,  0,  5408,   10,  20,  WED,   0,  0,  0),\r
160                     new TestCase(2334551.5,  0,  5440,    1,   1,  THU,   0,  0,  0),\r
161                     new TestCase(2334581.5,  0,  5440,    2,   1,  SAT,   0,  0,  0),\r
162                     new TestCase(2334610.5,  0,  5440,    3,   1,  SUN,   0,  0,  0),\r
163                     new TestCase(2334639.5,  0,  5440,    4,   1,  MON,   0,  0,  0),\r
164                     new TestCase(2334668.5,  0,  5440,    5,   1,  TUE,   0,  0,  0),\r
165                     new TestCase(2334698.5,  0,  5440,    6,   1,  THU,   0,  0,  0),\r
166                     new TestCase(2334728.5,  0,  5440,    7,   1,  SAT,   0,  0,  0),\r
167                     new TestCase(2334757.5,  0,  5440,    8,   1,  SUN,   0,  0,  0),\r
168                     new TestCase(2334787.5,  0,  5440,    9,   1,  TUE,   0,  0,  0),\r
169                     new TestCase(2334816.5,  0,  5440,   10,   1,  WED,   0,  0,  0),\r
170                     new TestCase(2334846.5,  0,  5440,   11,   1,  FRI,   0,  0,  0),\r
171                     new TestCase(2334848.5,  0,  5440,   11,   3,  SUN,   0,  0,  0),\r
172                     new TestCase(2334934.5,  0,  5441,    1,   1,  TUE,   0,  0,  0),\r
173                     new TestCase(2348020.5,  0,  5476,   12,   5,  FRI,   0,  0,  0),\r
174                     new TestCase(2366978.5,  0,  5528,   11,   4,  SUN,   0,  0,  0),\r
175                     new TestCase(2385648.5,  0,  5579,   12,  11,  MON,   0,  0,  0),\r
176                     new TestCase(2392825.5,  0,  5599,    8,  12,  WED,   0,  0,  0),\r
177                     new TestCase(2416223.5,  0,  5663,    8,  22,  SUN,   0,  0,  0),\r
178                     new TestCase(2425848.5,  0,  5689,   12,  19,  SUN,   0,  0,  0),\r
179                     new TestCase(2430266.5,  0,  5702,    1,   8,  MON,   0,  0,  0),\r
180                     new TestCase(2430833.5,  0,  5703,    8,  14,  MON,   0,  0,  0),\r
181                     new TestCase(2431004.5,  0,  5704,    1,   8,  THU,   0,  0,  0),\r
182                     new TestCase(2448698.5,  0,  5752,    7,  12,  TUE,   0,  0,  0),\r
183                     new TestCase(2450138.5,  0,  5756,    7,   5,  SUN,   0,  0,  0),\r
184                     new TestCase(2465737.5,  0,  5799,    2,  12,  WED,   0,  0,  0),\r
185                     new TestCase(2486076.5,  0,  5854,   12,   5,  SUN,   0,  0,  0),\r
186 \r
187                     // Additional test cases for bugs found during development\r
188                     //           G.YY/MM/DD  Era  Year  Month Day  WkDay Hour Min Sec\r
189                     new TestCase(1013, 9, 8, 0,  4774,    1,   1,  TUE,   0,  0,  0),\r
190                     new TestCase(1239, 9, 1, 0,  5000,    1,   1,  THU,   0,  0,  0),\r
191                     new TestCase(1240, 9,18, 0,  5001,    1,   1,  TUE,   0,  0,  0),\r
192 \r
193                     // Test cases taken from a table of 14 "year types" in the Help file\r
194                     // of the application "Hebrew Calendar"\r
195                     new TestCase(2456187.5,  0,  5773,    1,   1,  MON,   0,  0,  0),\r
196                     new TestCase(2459111.5,  0,  5781,    1,   1,  SAT,   0,  0,  0),\r
197                     new TestCase(2453647.5,  0,  5766,    1,   1,  TUE,   0,  0,  0),\r
198                     new TestCase(2462035.5,  0,  5789,    1,   1,  THU,   0,  0,  0),\r
199                     new TestCase(2458756.5,  0,  5780,    1,   1,  MON,   0,  0,  0),\r
200                     new TestCase(2460586.5,  0,  5785,    1,   1,  THU,   0,  0,  0),\r
201                     new TestCase(2463864.5,  0,  5794,    1,   1,  SAT,   0,  0,  0),\r
202                     new TestCase(2463481.5,  0,  5793,    1,   1,  MON,   0,  0,  0),\r
203                     new TestCase(2470421.5,  0,  5812,    1,   1,  THU,   0,  0,  0),\r
204                     new TestCase(2460203.5,  0,  5784,    1,   1,  SAT,   0,  0,  0),\r
205                     new TestCase(2459464.5,  0,  5782,    1,   1,  TUE,   0,  0,  0),\r
206                     new TestCase(2467142.5,  0,  5803,    1,   1,  MON,   0,  0,  0),\r
207                     new TestCase(2455448.5,  0,  5771,    1,   1,  THU,   0,  0,  0),\r
208                 \r
209                     // Test cases for JB#2327        \r
210                     // http://www.fourmilab.com/documents/calendar/\r
211                     // http://www.calendarhome.com/converter/\r
212 //                2452465.5, 2002, JULY, 10, 5762, AV, 1,\r
213 //                2452494.5, 2002, AUGUST, 8, 5762, AV, 30,\r
214 //                2452495.5, 2002, AUGUST, 9, 5762, ELUL, 1,\r
215 //                2452523.5, 2002, SEPTEMBER, 6, 5762, ELUL, 29,\r
216 //                2452524.5, 2002, SEPTEMBER, 7, 5763, TISHRI, 1,\r
217                     //         Julian Day  Era  Year  Month Day  WkDay Hour Min Sec\r
218                     new TestCase(2452465.5,  0,  5762,    AV+1,  1,  WED,   0,  0,  0),\r
219                     new TestCase(2452494.5,  0,  5762,    AV+1, 30,  THU,   0,  0,  0),\r
220                     new TestCase(2452495.5,  0,  5762,  ELUL+1,  1,  FRI,   0,  0,  0),\r
221                     new TestCase(2452523.5,  0,  5762,  ELUL+1, 29,  FRI,   0,  0,  0),\r
222                     new TestCase(2452524.5,  0,  5763,TISHRI+1,  1,  SAT,   0,  0,  0),\r
223                 };\r
224                 doTestCases(testCases, new HebrewCalendar());\r
225    \r
226         }catch(MissingResourceException ex){\r
227             warnln("Got Exception: "+ ex.getMessage());\r
228         }\r
229     }\r
230 \r
231     /**\r
232      * Problem reported by Armand Bendanan in which setting of the MONTH\r
233      * field in a Hebrew calendar causes the time fields to go negative.\r
234      */\r
235     public void TestTimeFields() {\r
236         try{\r
237             HebrewCalendar calendar = new HebrewCalendar(5761, 0, 11, 12, 28, 15);\r
238             calendar.set(Calendar.YEAR, 5717);\r
239             calendar.set(Calendar.MONTH, 2);\r
240             calendar.set(Calendar.DAY_OF_MONTH, 23);\r
241             if (calendar.get(Calendar.HOUR_OF_DAY) != 12) {\r
242                 errln("Fail: HebrewCalendar HOUR_OF_DAY = " + calendar.get(Calendar.HOUR_OF_DAY));\r
243             }\r
244         }catch(MissingResourceException ex){\r
245             warnln("Got Exception: "+ ex.getMessage());\r
246         }\r
247     }\r
248 \r
249     /**\r
250      * Problem reported by Armand Bendanan (armand.bendanan@free.fr)\r
251      * in which setting of the MONTH field in a Hebrew calendar to\r
252      * ELUL on non leap years causes the date to be set on TISHRI next year.\r
253      */\r
254     public void TestElulMonth() {\r
255         try{\r
256             HebrewCalendar cal = new HebrewCalendar();\r
257             // Leap years are:\r
258             // 3 6 8 11 14 17 19 (and so on - 19-year cycle)\r
259             for (int year=1; year<50; year++) {\r
260                 // I hope that year = 0 does not exists\r
261                 // because the test fails for it !\r
262                 cal.clear();\r
263                 \r
264                 cal.set(Calendar.YEAR, year);\r
265                 cal.set(Calendar.MONTH, ELUL);\r
266                 cal.set(Calendar.DAY_OF_MONTH, 1);\r
267                 \r
268                 int yact = cal.get(Calendar.YEAR);\r
269                 int mact = cal.get(Calendar.MONTH);\r
270                 \r
271                 if (year != yact || ELUL != mact) {\r
272                     errln("Fail: " + ELUL + "/" + year +\r
273                           " -> " +\r
274                           mact + "/" + yact);\r
275                 }\r
276             }\r
277         }catch(MissingResourceException ex){\r
278             warnln("Got Exception: "+ ex.getMessage());\r
279         }   \r
280     }\r
281     \r
282     /**\r
283      * Test of the behavior of the month field.  This requires special\r
284      * handling in the Hebrew calendar because of the pattern of leap\r
285      * years.\r
286      */\r
287     public void TestMonthMovement() {\r
288         try{\r
289             HebrewCalendar cal = new HebrewCalendar();\r
290             // Leap years are:\r
291             // 3 6 8 11 14 17 19 (and so on - 19-year cycle)\r
292             // We can't test complete() on some lines below because of ADAR_1 -- if\r
293             // the calendar is set to ADAR_1 on a non-leap year, the result is undefined.\r
294             int[] DATA = {\r
295                 // m1/y1 - month/year before (month is 1-based) \r
296                 // delta - amount to add to month field\r
297                 // m2/y2 - month/year after add(MONTH, delta)\r
298                 // m3/y3 - month/year after set(MONTH, m1+delta)\r
299               //m1  y1 delta  m2  y2  m3  y3\r
300                 10,  2,  +24,  9,  4,  9,  4,\r
301                 10,  2,  +60,  8,  7,  8,  7,\r
302                 1 ,  2,  +12,  1,  3, 13,  2, //*set != add; also see '*' below\r
303                 3 , 18,  -24,  4, 16,  4, 16,\r
304                 1 ,  6,  -24,  1,  4,  1,  4,\r
305                 4 ,  3,   +2,  6,  3,  6,  3, // Leap year - no skip 4,5,6,7,8\r
306                 8 ,  3,   -2,  6,  3,  6,  3, // Leap year - no skip\r
307                 4 ,  2,   +2,  7,  2,  7,  2, // Skip leap month 4,5,(6),7,8\r
308                 8 ,  2,   -2,  5,  2,  7,  2, //*Skip leap month going backward\r
309             };\r
310             for (int i=0; i<DATA.length; ) {\r
311                 int m = DATA[i++], y = DATA[i++];\r
312                 int monthDelta = DATA[i++];\r
313                 int m2 = DATA[i++], y2 = DATA[i++];\r
314                 int m3 = DATA[i++], y3 = DATA[i++];\r
315                 int mact, yact;\r
316     \r
317                 cal.clear();\r
318                 cal.set(Calendar.YEAR, y);\r
319                 cal.set(Calendar.MONTH, m-1);\r
320                 cal.add(Calendar.MONTH, monthDelta);\r
321                 yact = cal.get(Calendar.YEAR); mact = cal.get(Calendar.MONTH) + 1;\r
322                 if (y2 != yact || m2 != mact) {\r
323                     errln("Fail: " + m + "/" + y +\r
324                           " -> add(MONTH, " + monthDelta + ") -> " +\r
325                           mact + "/" + yact + ", expected " +\r
326                           m2 + "/" + y2);\r
327                     cal.clear();\r
328                     cal.set(Calendar.YEAR, y);\r
329                     cal.set(Calendar.MONTH, m-1);\r
330                     logln("Start: " + m + "/" + y);\r
331                     int delta = monthDelta > 0 ? 1 : -1;\r
332                     for (int c=0; c!=monthDelta; c+=delta) {\r
333                         cal.add(Calendar.MONTH, delta);\r
334                         logln("+ " + delta + " MONTH -> " +\r
335                               (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.YEAR));\r
336                     }\r
337                 }\r
338                 \r
339                 cal.clear();\r
340                 cal.set(Calendar.YEAR, y);\r
341                 cal.set(Calendar.MONTH, m + monthDelta - 1);\r
342                 yact = cal.get(Calendar.YEAR); mact = cal.get(Calendar.MONTH) + 1;\r
343                 if (y3 != yact || m3 != mact) {\r
344                     errln("Fail: " + (m+monthDelta) + "/" + y +\r
345                           " -> complete() -> " +\r
346                           mact + "/" + yact + ", expected " +\r
347                           m3 + "/" + y3);\r
348                 }\r
349             }\r
350         }catch(MissingResourceException ex){\r
351             warnln("Got Exception: "+ ex.getMessage());\r
352         }\r
353     }\r
354 \r
355     /**\r
356      * Test handling of ADAR_1.\r
357      */\r
358     /*\r
359     public void TestAdar1() {\r
360         HebrewCalendar cal = new HebrewCalendar();\r
361         cal.clear();\r
362         cal.set(Calendar.YEAR, 1903); // leap\r
363         cal.set(Calendar.MONTH, HebrewCalendar.ADAR_1);\r
364         logln("1903(leap)/ADAR_1 => " +\r
365               cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH)+1));\r
366 \r
367         cal.clear();\r
368         cal.set(Calendar.YEAR, 1904); // non-leap\r
369         cal.set(Calendar.MONTH, HebrewCalendar.ADAR_1);\r
370         logln("1904(non-leap)/ADAR_1 => " +\r
371               cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH)+1));\r
372     }\r
373     */\r
374 \r
375     /**\r
376      * With no fields set, the calendar should use default values.\r
377      */\r
378     public void TestDefaultFieldValues() {\r
379         try{\r
380             HebrewCalendar cal = new HebrewCalendar();\r
381             cal.clear();\r
382             logln("cal.clear() -> " + cal.getTime());\r
383         }catch(MissingResourceException ex){\r
384             warnln("could not load the locale data");\r
385         }\r
386     }\r
387 \r
388     /**\r
389      * Test limits of the Hebrew calendar\r
390      */\r
391     public void TestLimits() {\r
392         Calendar cal = Calendar.getInstance();\r
393         cal.set(2007, Calendar.JANUARY, 1);\r
394         HebrewCalendar hebrew = new HebrewCalendar();\r
395         doLimitsTest(hebrew, null, cal.getTime());\r
396         doTheoreticalLimitsTest(hebrew, true);\r
397     }\r
398 \r
399     public void TestCoverage() {\r
400         try{\r
401             {\r
402                 // new HebrewCalendar(TimeZone)\r
403                 HebrewCalendar cal = new HebrewCalendar(TimeZone.getDefault());\r
404                 if(cal == null){\r
405                     errln("could not create HebrewCalendar with TimeZone");\r
406                 }\r
407             }\r
408     \r
409             {\r
410                 // new HebrewCalendar(ULocale)\r
411                 HebrewCalendar cal = new HebrewCalendar(ULocale.getDefault());\r
412                 if(cal == null){\r
413                     errln("could not create HebrewCalendar with ULocale");\r
414                 }\r
415             }\r
416                 \r
417             {\r
418                 // new HebrewCalendar(Locale)\r
419                 HebrewCalendar cal = new HebrewCalendar(Locale.getDefault());\r
420                 if(cal == null){\r
421                     errln("could not create HebrewCalendar with locale");\r
422                 }\r
423             }\r
424         \r
425             {\r
426                 // new HebrewCalendar(Date)\r
427                 HebrewCalendar cal = new HebrewCalendar(new Date());\r
428                 if(cal == null){\r
429                     errln("could not create HebrewCalendar with date");\r
430                 }\r
431             }\r
432         \r
433             {\r
434                 // data\r
435                 HebrewCalendar cal = new HebrewCalendar(2800, HebrewCalendar.SHEVAT, 1);\r
436                 Date time = cal.getTime();\r
437         \r
438                 String[] calendarLocales = {\r
439                 "iw_IL"\r
440                 };\r
441         \r
442                 String[] formatLocales = {\r
443                 "en", "fi", "fr", "hu", "iw", "nl"\r
444                 };\r
445                 for (int i = 0; i < calendarLocales.length; ++i) {\r
446                     String calLocName = calendarLocales[i];\r
447                     Locale calLocale = LocaleUtility.getLocaleFromName(calLocName);\r
448                     cal = new HebrewCalendar(calLocale);\r
449             \r
450                     for (int j = 0; j < formatLocales.length; ++j) {\r
451                         String locName = formatLocales[j];\r
452                         Locale formatLocale = LocaleUtility.getLocaleFromName(locName);\r
453                         DateFormat format = DateFormat.getDateTimeInstance(cal, DateFormat.FULL, DateFormat.FULL, formatLocale);\r
454                         logln(calLocName + "/" + locName + " --> " + format.format(time));\r
455                     }\r
456                 }\r
457             }\r
458         }catch( MissingResourceException ex){\r
459             warnln("Could not load the locale data. "+ ex.getMessage());\r
460         }\r
461     }\r
462     public void Test1624() {\r
463 \r
464         HebrewCalendar hc = new HebrewCalendar (5742, HebrewCalendar.AV, 22);\r
465         DateFormat df = hc.getDateTimeFormat(DateFormat.FULL, DateFormat.FULL, Locale.getDefault());\r
466         String dateString = df.format(hc.getTime());\r
467      \r
468         for (int year = 5600; year < 5800; year ++) {\r
469             boolean leapYear = HebrewCalendar.isLeapYear (year);\r
470             for (int month = HebrewCalendar.TISHRI; month <= HebrewCalendar.ELUL;month++) {\r
471                 // skip the adar 1 month if year is not a leap year\r
472                 if (leapYear == false && month == HebrewCalendar.ADAR_1) {\r
473                     continue;\r
474                 }\r
475                 int day = 15;\r
476                 hc = new HebrewCalendar (year, month, day);\r
477 \r
478                 dateString = df.format(hc.getTime());\r
479                 int dayHC = hc.get (HebrewCalendar.DATE);\r
480                 int monthHC = hc.get (HebrewCalendar.MONTH);\r
481                 int yearHC = hc.get (HebrewCalendar.YEAR);\r
482 \r
483                 String header = "year:" + year + " isleap:" + leapYear + " " + dateString;\r
484                 if (dayHC != day) {\r
485                     errln (header + " ==> day:" + dayHC + " incorrect, should be:" + day);\r
486                     break;\r
487                 }\r
488                 if (monthHC != month) {\r
489                     errln (header + " ==> month:" + monthHC + " incorrect, should be:" + month);\r
490                     break;\r
491                 }\r
492                 if (yearHC != year) {\r
493                     errln (header + " ==> year:" + yearHC + " incorrecte, should be:" + year);\r
494                     break;\r
495                 }\r
496             }\r
497         }       \r
498     }\r
499 }\r