Search in sources :

Example 6 with HebrewCalendar

use of android.icu.util.HebrewCalendar in project j2objc by google.

the class HebrewTest method TestDefaultFieldValues.

/**
 * Test handling of ADAR_1.
 */
/*
    @Test
    public void TestAdar1() {
        HebrewCalendar cal = new HebrewCalendar();
        cal.clear();
        cal.set(Calendar.YEAR, 1903); // leap
        cal.set(Calendar.MONTH, HebrewCalendar.ADAR_1);
        logln("1903(leap)/ADAR_1 => " +
              cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH)+1));

        cal.clear();
        cal.set(Calendar.YEAR, 1904); // non-leap
        cal.set(Calendar.MONTH, HebrewCalendar.ADAR_1);
        logln("1904(non-leap)/ADAR_1 => " +
              cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH)+1));
    }
    */
/**
 * With no fields set, the calendar should use default values.
 */
@Test
public void TestDefaultFieldValues() {
    try {
        HebrewCalendar cal = new HebrewCalendar();
        cal.clear();
        logln("cal.clear() -> " + cal.getTime());
    } catch (MissingResourceException ex) {
        warnln("could not load the locale data");
    }
}
Also used : HebrewCalendar(android.icu.util.HebrewCalendar) MissingResourceException(java.util.MissingResourceException) Test(org.junit.Test)

Example 7 with HebrewCalendar

use of android.icu.util.HebrewCalendar in project j2objc by google.

the class HebrewTest method TestMonthValidation.

// Test case for Ticket#10313. HebrewCalendar requires
// special handling for validating month value, because
// month Adar I is only available in leap years.
@Test
public void TestMonthValidation() {
    HebrewCalendar cal = new HebrewCalendar();
    cal.setLenient(false);
    // 5776 is a leap year and has month Adar I
    cal.set(5776, ADAR_1, 1);
    try {
        /* Date d = */
        cal.getTime();
    } catch (IllegalArgumentException e) {
        errln("Fail: 5776 Adar I 1 is a valid date.");
    }
    // 5777 is NOT a lear year and does not have month Adar I
    cal.set(5777, ADAR_1, 1);
    try {
        /* Date d = */
        cal.getTime();
        errln("Fail: IllegalArgumentException should be thrown for input date 5777 Adar I 1.");
    } catch (IllegalArgumentException e) {
        logln("Info: IllegalArgumentException, because 5777 Adar I 1 is not a valid date.");
    }
}
Also used : HebrewCalendar(android.icu.util.HebrewCalendar) Test(org.junit.Test)

Example 8 with HebrewCalendar

use of android.icu.util.HebrewCalendar in project j2objc by google.

the class HebrewTest method TestTimeFields.

/**
 * Problem reported by Armand Bendanan in which setting of the MONTH
 * field in a Hebrew calendar causes the time fields to go negative.
 */
@Test
public void TestTimeFields() {
    try {
        HebrewCalendar calendar = new HebrewCalendar(5761, 0, 11, 12, 28, 15);
        calendar.set(Calendar.YEAR, 5717);
        calendar.set(Calendar.MONTH, 2);
        calendar.set(Calendar.DAY_OF_MONTH, 23);
        if (calendar.get(Calendar.HOUR_OF_DAY) != 12) {
            errln("Fail: HebrewCalendar HOUR_OF_DAY = " + calendar.get(Calendar.HOUR_OF_DAY));
        }
    } catch (MissingResourceException ex) {
        warnln("Got Exception: " + ex.getMessage());
    }
}
Also used : HebrewCalendar(android.icu.util.HebrewCalendar) MissingResourceException(java.util.MissingResourceException) Test(org.junit.Test)

Example 9 with HebrewCalendar

use of android.icu.util.HebrewCalendar in project j2objc by google.

the class HebrewTest method TestLimits.

/**
 * Test limits of the Hebrew calendar
 */
@Test
public void TestLimits() {
    Calendar cal = Calendar.getInstance();
    cal.set(2007, Calendar.JANUARY, 1);
    HebrewCalendar hebrew = new HebrewCalendar();
    doLimitsTest(hebrew, null, cal.getTime());
    doTheoreticalLimitsTest(hebrew, true);
}
Also used : HebrewCalendar(android.icu.util.HebrewCalendar) HebrewCalendar(android.icu.util.HebrewCalendar) Calendar(android.icu.util.Calendar) Test(org.junit.Test)

Example 10 with HebrewCalendar

use of android.icu.util.HebrewCalendar in project j2objc by google.

the class HebrewTest method Test1624.

@Test
public void Test1624() {
    HebrewCalendar hc = new HebrewCalendar(5742, HebrewCalendar.AV, 22);
    DateFormat df = hc.getDateTimeFormat(DateFormat.FULL, DateFormat.FULL, Locale.getDefault());
    String dateString = df.format(hc.getTime());
    for (int year = 5600; year < 5800; year++) {
        boolean leapYear = HebrewCalendar.isLeapYear(year);
        for (int month = HebrewCalendar.TISHRI; month <= HebrewCalendar.ELUL; month++) {
            // skip the adar 1 month if year is not a leap year
            if (leapYear == false && month == HebrewCalendar.ADAR_1) {
                continue;
            }
            int day = 15;
            hc = new HebrewCalendar(year, month, day);
            dateString = df.format(hc.getTime());
            int dayHC = hc.get(HebrewCalendar.DATE);
            int monthHC = hc.get(HebrewCalendar.MONTH);
            int yearHC = hc.get(HebrewCalendar.YEAR);
            String header = "year:" + year + " isleap:" + leapYear + " " + dateString;
            if (dayHC != day) {
                errln(header + " ==> day:" + dayHC + " incorrect, should be:" + day);
                break;
            }
            if (monthHC != month) {
                errln(header + " ==> month:" + monthHC + " incorrect, should be:" + month);
                break;
            }
            if (yearHC != year) {
                errln(header + " ==> year:" + yearHC + " incorrecte, should be:" + year);
                break;
            }
        }
    }
}
Also used : HebrewCalendar(android.icu.util.HebrewCalendar) DateFormat(android.icu.text.DateFormat) Test(org.junit.Test)

Aggregations

HebrewCalendar (android.icu.util.HebrewCalendar)11 Test (org.junit.Test)11 MissingResourceException (java.util.MissingResourceException)6 DateFormat (android.icu.text.DateFormat)2 Calendar (android.icu.util.Calendar)2 ChineseDateFormat (android.icu.text.ChineseDateFormat)1 SimpleDateFormat (android.icu.text.SimpleDateFormat)1 BuddhistCalendar (android.icu.util.BuddhistCalendar)1 ChineseCalendar (android.icu.util.ChineseCalendar)1 GregorianCalendar (android.icu.util.GregorianCalendar)1 IslamicCalendar (android.icu.util.IslamicCalendar)1 JapaneseCalendar (android.icu.util.JapaneseCalendar)1 TimeZone (android.icu.util.TimeZone)1 ULocale (android.icu.util.ULocale)1 FieldPosition (java.text.FieldPosition)1 ParsePosition (java.text.ParsePosition)1 Date (java.util.Date)1