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