Search in sources :

Example 11 with IslamicCalendar

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

the class IslamicTest method TestCreationByLocale.

@Test
public void TestCreationByLocale() {
    ULocale islamicLoc = new ULocale("ar_SA@calendar=islamic-umalqura");
    IslamicCalendar is_cal = new IslamicCalendar(islamicLoc);
    String thisCalcType = is_cal.getType();
    if (!"islamic-umalqura".equalsIgnoreCase(thisCalcType)) {
        errln("non umalqura calc type generated - " + thisCalcType);
    }
    islamicLoc = new ULocale("ar_SA@calendar=islamic-civil");
    is_cal = new IslamicCalendar(islamicLoc);
    thisCalcType = is_cal.getType();
    if (!"islamic-civil".equalsIgnoreCase(thisCalcType)) {
        errln("non civil calc type generated - " + thisCalcType);
    }
    islamicLoc = new ULocale("ar_SA@calendar=islamic-tbla");
    is_cal = new IslamicCalendar(islamicLoc);
    thisCalcType = is_cal.getType();
    if (!"islamic-tbla".equalsIgnoreCase(thisCalcType)) {
        errln("non tbla calc type generated - " + thisCalcType);
    }
    islamicLoc = new ULocale("ar_SA@calendar=islamic-xyzzy");
    is_cal = new IslamicCalendar(islamicLoc);
    thisCalcType = is_cal.getType();
    if (!"islamic".equalsIgnoreCase(thisCalcType)) {
        errln("incorrect default calc type generated - " + thisCalcType);
    }
}
Also used : ULocale(android.icu.util.ULocale) IslamicCalendar(android.icu.util.IslamicCalendar) Test(org.junit.Test)

Example 12 with IslamicCalendar

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

the class IslamicTest method TestCivilCases.

/**
 * A huge list of test cases to make sure that computeTime and computeFields
 * work properly for a wide range of data in the civil calendar.
 */
@Test
public void TestCivilCases() {
    final TestCase[] tests = { // Julian Day  Era  Year  Month Day  WkDay Hour Min Sec
    new TestCase(1507231.5, 0, -1245, 12, 9, SUN, 0, 0, 0), new TestCase(1660037.5, 0, -813, 2, 23, WED, 0, 0, 0), new TestCase(1746893.5, 0, -568, 4, 1, WED, 0, 0, 0), new TestCase(1770641.5, 0, -501, 4, 6, SUN, 0, 0, 0), new TestCase(1892731.5, 0, -157, 10, 17, WED, 0, 0, 0), new TestCase(1931579.5, 0, -47, 6, 3, MON, 0, 0, 0), new TestCase(1974851.5, 0, 75, 7, 13, SAT, 0, 0, 0), new TestCase(2091164.5, 0, 403, 10, 5, SUN, 0, 0, 0), new TestCase(2121509.5, 0, 489, 5, 22, SUN, 0, 0, 0), new TestCase(2155779.5, 0, 586, 2, 7, FRI, 0, 0, 0), new TestCase(2174029.5, 0, 637, 8, 7, SAT, 0, 0, 0), new TestCase(2191584.5, 0, 687, 2, 20, FRI, 0, 0, 0), new TestCase(2195261.5, 0, 697, 7, 7, SUN, 0, 0, 0), new TestCase(2229274.5, 0, 793, 7, 1, SUN, 0, 0, 0), new TestCase(2245580.5, 0, 839, 7, 6, WED, 0, 0, 0), new TestCase(2266100.5, 0, 897, 6, 1, SAT, 0, 0, 0), new TestCase(2288542.5, 0, 960, 9, 30, SAT, 0, 0, 0), new TestCase(2290901.5, 0, 967, 5, 27, SAT, 0, 0, 0), new TestCase(2323140.5, 0, 1058, 5, 18, WED, 0, 0, 0), new TestCase(2334848.5, 0, 1091, 6, 2, SUN, 0, 0, 0), new TestCase(2348020.5, 0, 1128, 8, 4, FRI, 0, 0, 0), new TestCase(2366978.5, 0, 1182, 2, 3, SUN, 0, 0, 0), new TestCase(2385648.5, 0, 1234, 10, 10, MON, 0, 0, 0), new TestCase(2392825.5, 0, 1255, 1, 11, WED, 0, 0, 0), new TestCase(2416223.5, 0, 1321, 1, 21, SUN, 0, 0, 0), new TestCase(2425848.5, 0, 1348, 3, 19, SUN, 0, 0, 0), new TestCase(2430266.5, 0, 1360, 9, 8, MON, 0, 0, 0), new TestCase(2430833.5, 0, 1362, 4, 13, MON, 0, 0, 0), new TestCase(2431004.5, 0, 1362, 10, 7, THU, 0, 0, 0), new TestCase(2448698.5, 0, 1412, 9, 13, TUE, 0, 0, 0), new TestCase(2450138.5, 0, 1416, 10, 5, SUN, 0, 0, 0), new TestCase(2465737.5, 0, 1460, 10, 12, WED, 0, 0, 0), new TestCase(2486076.5, 0, 1518, 3, 5, SUN, 0, 0, 0) };
    IslamicCalendar civilCalendar = newCivil();
    civilCalendar.setLenient(true);
    doTestCases(tests, civilCalendar);
}
Also used : IslamicCalendar(android.icu.util.IslamicCalendar) Test(org.junit.Test)

Example 13 with IslamicCalendar

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

the class IslamicTest method TestSerialization8449.

@Test
public void TestSerialization8449() {
    try {
        ByteArrayOutputStream icuStream = new ByteArrayOutputStream();
        IslamicCalendar tstCalendar = new IslamicCalendar();
        tstCalendar.setCivil(false);
        // with seconds (not ms) cleared.
        long expectMillis = 1187912520931L;
        tstCalendar.setTimeInMillis(expectMillis);
        logln("instantiated: " + tstCalendar);
        logln("getMillis: " + tstCalendar.getTimeInMillis());
        tstCalendar.set(IslamicCalendar.SECOND, 0);
        logln("setSecond=0: " + tstCalendar);
        {
            long gotMillis = tstCalendar.getTimeInMillis();
            if (gotMillis != expectMillis) {
                errln("expect millis " + expectMillis + " but got " + gotMillis);
            } else {
                logln("getMillis: " + gotMillis);
            }
        }
        ObjectOutputStream icuOut = new ObjectOutputStream(icuStream);
        icuOut.writeObject(tstCalendar);
        icuOut.flush();
        icuOut.close();
        ObjectInputStream icuIn = new ObjectInputStream(new ByteArrayInputStream(icuStream.toByteArray()));
        tstCalendar = null;
        tstCalendar = (IslamicCalendar) icuIn.readObject();
        logln("serialized back in: " + tstCalendar);
        {
            long gotMillis = tstCalendar.getTimeInMillis();
            if (gotMillis != expectMillis) {
                errln("expect millis " + expectMillis + " but got " + gotMillis);
            } else {
                logln("getMillis: " + gotMillis);
            }
        }
        tstCalendar.set(IslamicCalendar.SECOND, 0);
        logln("setSecond=0: " + tstCalendar);
        {
            long gotMillis = tstCalendar.getTimeInMillis();
            if (gotMillis != expectMillis) {
                errln("expect millis " + expectMillis + " after stream and setSecond but got " + gotMillis);
            } else {
                logln("getMillis after stream and setSecond: " + gotMillis);
            }
        }
    } catch (IOException e) {
        errln(e.toString());
        e.printStackTrace();
    } catch (ClassNotFoundException cnf) {
        errln(cnf.toString());
        cnf.printStackTrace();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) IslamicCalendar(android.icu.util.IslamicCalendar) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 14 with IslamicCalendar

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

the class DateFormatRegressionTest method TestHindiArabicDigits.

@Test
public void TestHindiArabicDigits() {
    String s;
    char first;
    String what;
    {
        DateFormat df = DateFormat.getInstance(new GregorianCalendar(), new ULocale("hi_IN@numbers=deva"));
        what = "Gregorian Calendar, hindi";
        s = df.format(new Date(0));
        /* 31/12/1969 */
        logln(what + "=" + s);
        first = s.charAt(0);
        if (first < kHindiZero || first > (kHindiZero + 9)) {
            errln(what + "- wrong digit,  got " + s + " (integer digit value " + new Integer((int) first).toString());
        }
    }
    {
        DateFormat df = DateFormat.getInstance(new IslamicCalendar(), new Locale("ar", "IQ"));
        s = df.format(new Date(0));
        /* 21/10/1989 */
        what = "Islamic Calendar, Arabic";
        logln(what + ": " + s);
        first = s.charAt(0);
        if (first < kArabicZero || first > (kArabicZero + 9)) {
            errln(what + " wrong digit, got " + s + " (integer digit value " + new Integer((int) first).toString());
        }
    }
    {
        DateFormat df = DateFormat.getInstance(new GregorianCalendar(), new Locale("ar", "IQ"));
        s = df.format(new Date(0));
        /* 31/12/1969 */
        what = "Gregorian,  ar_IQ, df.getInstance";
        logln(what + ": " + s);
        first = s.charAt(0);
        if (first < kArabicZero || first > (kArabicZero + 9)) {
            errln(what + " wrong  digit but got " + s + " (integer digit value " + new Integer((int) first).toString());
        }
    }
    {
        DateFormat df = DateFormat.getInstance(new GregorianCalendar(), new Locale("mt", "MT"));
        s = df.format(new Date(0));
        /* 31/12/1969 */
        what = "Gregorian,  mt_MT, df.getInstance";
        logln(what + ": " + s);
        first = s.charAt(0);
        if (first < kLatinZero || first > (kLatinZero + 9)) {
            errln(what + " wrong  digit but got " + s + " (integer digit value " + new Integer((int) first).toString());
        }
    }
    {
        DateFormat df = DateFormat.getInstance(new IslamicCalendar(), new Locale("ar", "IQ"));
        s = df.format(new Date(0));
        /* 31/12/1969 */
        what = "Islamic calendar, ar_IQ, df.getInstance";
        logln(what + ": " + s);
        first = s.charAt(0);
        if (first < kArabicZero || first > (kArabicZero + 9)) {
            errln(what + " wrong  digit but got " + s + " (integer digit value " + new Integer((int) first).toString());
        }
    }
    {
        DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, new Locale("ar", "IQ"));
        s = df.format(new Date(0));
        /* 31/12/1969 */
        what = "ar_IQ, getDateTimeInstance";
        logln(what + ": " + s);
        first = s.charAt(0);
        if (first < kArabicZero || first > (kArabicZero + 9)) {
            errln(what + " wrong  digit but got " + s + " (integer digit value " + new Integer((int) first).toString());
        }
    }
    {
        DateFormat df = DateFormat.getInstance(new JapaneseCalendar(), new Locale("ar", "IQ"));
        s = df.format(new Date(0));
        /* 31/12/1969 */
        what = "ar_IQ, Japanese Calendar, getInstance";
        logln(what + ": " + s);
        first = s.charAt(0);
        if (first < kArabicZero || first > (kArabicZero + 9)) {
            errln(what + " wrong  digit but got " + s + " (integer digit value " + new Integer((int) first).toString());
        }
    }
}
Also used : ULocale(android.icu.util.ULocale) Locale(java.util.Locale) ULocale(android.icu.util.ULocale) DateFormat(android.icu.text.DateFormat) SimpleDateFormat(android.icu.text.SimpleDateFormat) GregorianCalendar(android.icu.util.GregorianCalendar) Date(java.util.Date) JapaneseCalendar(android.icu.util.JapaneseCalendar) IslamicCalendar(android.icu.util.IslamicCalendar) Test(org.junit.Test)

Example 15 with IslamicCalendar

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

the class DateFormatRegressionTest method Test5006GetShortMonths.

// Note: The purpose of this test case is a little bit questionable. This test
// case expects Islamic month name is different from Gregorian month name.
// However, some locales (in this code, zh_CN) may intentionally use the same
// month name for both Gregorian and Islamic calendars. See #9645.
@Test
public void Test5006GetShortMonths() throws Exception {
    // Currently supported NLV locales
    // We don't support 'en' alone
    Locale ENGLISH = new Locale("en", "US");
    Locale ARABIC = new Locale("ar", "");
    Locale CZECH = new Locale("cs", "");
    Locale GERMAN = new Locale("de", "");
    Locale GREEK = new Locale("el", "");
    Locale SPANISH = new Locale("es", "");
    Locale FRENCH = new Locale("fr", "");
    Locale HUNGARIAN = new Locale("hu", "");
    Locale ITALIAN = new Locale("it", "");
    Locale HEBREW = new Locale("iw", "");
    Locale JAPANESE = new Locale("ja", "");
    Locale KOREAN = new Locale("ko", "");
    Locale POLISH = new Locale("pl", "");
    Locale PORTUGUESE = new Locale("pt", "BR");
    Locale RUSSIAN = new Locale("ru", "");
    Locale TURKISH = new Locale("tr", "");
    Locale CHINESE_SIMPLIFIED = new Locale("zh", "CN");
    Locale CHINESE_TRADITIONAL = new Locale("zh", "TW");
    Locale[] locales = new Locale[] { ENGLISH, ARABIC, CZECH, GERMAN, GREEK, SPANISH, FRENCH, HUNGARIAN, ITALIAN, HEBREW, JAPANESE, KOREAN, POLISH, PORTUGUESE, RUSSIAN, TURKISH, CHINESE_SIMPLIFIED, CHINESE_TRADITIONAL };
    String[] islamicCivilTwelfthMonthLocalized = new String[locales.length];
    String[] islamicTwelfthMonthLocalized = new String[locales.length];
    String[] gregorianTwelfthMonthLocalized = new String[locales.length];
    for (int i = 0; i < locales.length; i++) {
        Locale locale = locales[i];
        // Islamic
        android.icu.util.Calendar islamicCivilCalendar = new android.icu.util.IslamicCalendar(locale);
        android.icu.text.SimpleDateFormat islamicCivilDateFormat = (android.icu.text.SimpleDateFormat) islamicCivilCalendar.getDateTimeFormat(android.icu.text.DateFormat.FULL, -1, locale);
        android.icu.text.DateFormatSymbols islamicCivilDateFormatSymbols = islamicCivilDateFormat.getDateFormatSymbols();
        String[] shortMonthsCivil = islamicCivilDateFormatSymbols.getShortMonths();
        String twelfthMonthLocalizedCivil = shortMonthsCivil[11];
        islamicCivilTwelfthMonthLocalized[i] = twelfthMonthLocalizedCivil;
        android.icu.util.IslamicCalendar islamicCalendar = new android.icu.util.IslamicCalendar(locale);
        islamicCalendar.setCivil(false);
        android.icu.text.SimpleDateFormat islamicDateFormat = (android.icu.text.SimpleDateFormat) islamicCalendar.getDateTimeFormat(android.icu.text.DateFormat.FULL, -1, locale);
        android.icu.text.DateFormatSymbols islamicDateFormatSymbols = islamicDateFormat.getDateFormatSymbols();
        String[] shortMonths = islamicDateFormatSymbols.getShortMonths();
        String twelfthMonthLocalized = shortMonths[11];
        islamicTwelfthMonthLocalized[i] = twelfthMonthLocalized;
        // Gregorian
        android.icu.util.Calendar gregorianCalendar = new android.icu.util.GregorianCalendar(locale);
        android.icu.text.SimpleDateFormat gregorianDateFormat = (android.icu.text.SimpleDateFormat) gregorianCalendar.getDateTimeFormat(android.icu.text.DateFormat.FULL, -1, locale);
        android.icu.text.DateFormatSymbols gregorianDateFormatSymbols = gregorianDateFormat.getDateFormatSymbols();
        shortMonths = gregorianDateFormatSymbols.getShortMonths();
        twelfthMonthLocalized = shortMonths[11];
        gregorianTwelfthMonthLocalized[i] = twelfthMonthLocalized;
    }
    // Compare
    for (int i = 0; i < locales.length; i++) {
        String gregorianTwelfthMonth = gregorianTwelfthMonthLocalized[i];
        String islamicCivilTwelfthMonth = islamicCivilTwelfthMonthLocalized[i];
        String islamicTwelfthMonth = islamicTwelfthMonthLocalized[i];
        logln(locales[i] + ": g:" + gregorianTwelfthMonth + ", ic:" + islamicCivilTwelfthMonth + ", i:" + islamicTwelfthMonth);
        if (gregorianTwelfthMonth.equalsIgnoreCase(islamicTwelfthMonth)) {
            // Simplified Chinese uses numeric month for both Gregorian/Islamic calendars
            if (locales[i] != CHINESE_SIMPLIFIED) {
                errln(locales[i] + ": gregorian and islamic are same: " + gregorianTwelfthMonth + ", " + islamicTwelfthMonth);
            }
        }
        if (gregorianTwelfthMonth.equalsIgnoreCase(islamicCivilTwelfthMonth)) {
            // Simplified Chinese uses numeric month for both Gregorian/Islamic calendars
            if (locales[i] != CHINESE_SIMPLIFIED) {
                errln(locales[i] + ": gregorian and islamic-civil are same: " + gregorianTwelfthMonth + ", " + islamicCivilTwelfthMonth);
            }
        }
        if (!islamicTwelfthMonth.equalsIgnoreCase(islamicCivilTwelfthMonth)) {
            errln(locales[i] + ": islamic-civil and islamic are NOT same: " + islamicCivilTwelfthMonth + ", " + islamicTwelfthMonth);
        }
    }
}
Also used : ULocale(android.icu.util.ULocale) Locale(java.util.Locale) IslamicCalendar(android.icu.util.IslamicCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) SimpleDateFormat(android.icu.text.SimpleDateFormat) Calendar(android.icu.util.Calendar) SimpleDateFormat(android.icu.text.SimpleDateFormat) IslamicCalendar(android.icu.util.IslamicCalendar) Test(org.junit.Test)

Aggregations

IslamicCalendar (android.icu.util.IslamicCalendar)17 Test (org.junit.Test)14 GregorianCalendar (android.icu.util.GregorianCalendar)7 ULocale (android.icu.util.ULocale)7 SimpleDateFormat (android.icu.text.SimpleDateFormat)6 Calendar (android.icu.util.Calendar)5 JapaneseCalendar (android.icu.util.JapaneseCalendar)4 Date (java.util.Date)4 DateFormat (android.icu.text.DateFormat)3 BuddhistCalendar (android.icu.util.BuddhistCalendar)3 TimeZone (android.icu.util.TimeZone)3 IOException (java.io.IOException)3 GlobalizationPreferences (android.icu.util.GlobalizationPreferences)2 Locale (java.util.Locale)2 ChineseDateFormat (android.icu.text.ChineseDateFormat)1 ChineseCalendar (android.icu.util.ChineseCalendar)1 HebrewCalendar (android.icu.util.HebrewCalendar)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1