Search in sources :

Example 11 with DateFormatSymbols

use of android.icu.text.DateFormatSymbols in project j2objc by google.

the class DateFormatTest method TestChineseDateFormatLocalizedPatternChars.

@Test
public void TestChineseDateFormatLocalizedPatternChars() {
    // jb 4904
    // make sure we can display localized versions of the chars used in the default
    // chinese date format patterns
    Calendar chineseCalendar = new ChineseCalendar();
    chineseCalendar.setTimeInMillis((new Date()).getTime());
    SimpleDateFormat longChineseDateFormat = (SimpleDateFormat) chineseCalendar.getDateTimeFormat(DateFormat.LONG, DateFormat.LONG, Locale.CHINA);
    DateFormatSymbols dfs = new ChineseDateFormatSymbols(chineseCalendar, Locale.CHINA);
    longChineseDateFormat.setDateFormatSymbols(dfs);
    // This next line throws the exception
    try {
        longChineseDateFormat.toLocalizedPattern();
    } catch (Exception e) {
        errln("could not localized pattern: " + e.getMessage());
    }
}
Also used : ChineseCalendar(android.icu.util.ChineseCalendar) ChineseDateFormatSymbols(android.icu.text.ChineseDateFormatSymbols) BuddhistCalendar(android.icu.util.BuddhistCalendar) HebrewCalendar(android.icu.util.HebrewCalendar) IslamicCalendar(android.icu.util.IslamicCalendar) ChineseCalendar(android.icu.util.ChineseCalendar) GregorianCalendar(android.icu.util.GregorianCalendar) Calendar(android.icu.util.Calendar) JapaneseCalendar(android.icu.util.JapaneseCalendar) DateFormatSymbols(android.icu.text.DateFormatSymbols) ChineseDateFormatSymbols(android.icu.text.ChineseDateFormatSymbols) SimpleDateFormat(android.icu.text.SimpleDateFormat) Date(java.util.Date) ParseException(java.text.ParseException) IOException(java.io.IOException) Test(org.junit.Test)

Example 12 with DateFormatSymbols

use of android.icu.text.DateFormatSymbols in project j2objc by google.

the class IntlTestDateFormatSymbols method TestSymbols.

// Test the API of DateFormatSymbols; primarily a simple get/set set.
@Test
public void TestSymbols() {
    DateFormatSymbols fr = new DateFormatSymbols(Locale.FRENCH);
    DateFormatSymbols fr2 = new DateFormatSymbols(Locale.FRENCH);
    DateFormatSymbols en = new DateFormatSymbols(Locale.ENGLISH);
    DateFormatSymbols zhChiCal = new DateFormatSymbols(new ULocale("zh@calendar=chinese"));
    if (en.equals(fr)) {
        errln("ERROR: English DateFormatSymbols equal to French");
    }
    // just do some VERY basic tests to make sure that get/set work
    long count;
    final String[] eras = en.getEras();
    fr.setEras(eras);
    final String[] eras1 = fr.getEras();
    count = eras.length;
    if (count != eras1.length) {
        errln("ERROR: setEras() failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!eras[i].equals(eras1[i])) {
                errln("ERROR: setEras() failed (different string values)");
            }
        }
    }
    final String[] months = en.getMonths();
    fr.setMonths(months);
    final String[] months1 = fr.getMonths();
    count = months.length;
    if (count != months1.length) {
        errln("ERROR: setMonths() failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!months[i].equals(months1[i])) {
                errln("ERROR: setMonths() failed (different string values)");
            }
        }
    }
    final String[] shortMonths = en.getShortMonths();
    fr.setShortMonths(shortMonths);
    final String[] shortMonths1 = fr.getShortMonths();
    count = shortMonths.length;
    if (count != shortMonths1.length) {
        errln("ERROR: setShortMonths() failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!shortMonths[i].equals(shortMonths1[i])) {
                errln("ERROR: setShortMonths() failed (different string values)");
            }
        }
    }
    final String[] wideMonths = en.getMonths(DateFormatSymbols.FORMAT, DateFormatSymbols.WIDE);
    fr2.setMonths(wideMonths, DateFormatSymbols.FORMAT, DateFormatSymbols.WIDE);
    final String[] wideMonths1 = fr2.getMonths(DateFormatSymbols.FORMAT, DateFormatSymbols.WIDE);
    count = wideMonths.length;
    if (count != wideMonths1.length) {
        errln("ERROR: setMonths(FORMAT,WIDE) failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!wideMonths[i].equals(wideMonths1[i])) {
                errln("ERROR: setMonths(FORMAT,WIDE) failed (different string values)");
            }
        }
    }
    final String[] abbrMonths = en.getMonths(DateFormatSymbols.FORMAT, DateFormatSymbols.ABBREVIATED);
    fr2.setMonths(abbrMonths, DateFormatSymbols.FORMAT, DateFormatSymbols.ABBREVIATED);
    final String[] abbrMonths1 = fr2.getMonths(DateFormatSymbols.FORMAT, DateFormatSymbols.ABBREVIATED);
    count = abbrMonths.length;
    if (count != abbrMonths1.length) {
        errln("ERROR: setMonths(FORMAT,ABBREVIATED) failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!abbrMonths[i].equals(abbrMonths1[i])) {
                errln("ERROR: setMonths(FORMAT,ABBREVIATED) failed (different string values)");
            }
        }
    }
    final String[] narrowMonths = en.getMonths(DateFormatSymbols.FORMAT, DateFormatSymbols.NARROW);
    fr.setMonths(narrowMonths, DateFormatSymbols.FORMAT, DateFormatSymbols.NARROW);
    final String[] narrowMonths1 = fr.getMonths(DateFormatSymbols.FORMAT, DateFormatSymbols.NARROW);
    count = narrowMonths.length;
    if (count != narrowMonths1.length) {
        errln("ERROR: setMonths(FORMAT,NARROW) failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!narrowMonths[i].equals(narrowMonths1[i])) {
                errln("ERROR: setMonths(FORMAT,NARROW) failed (different string values)");
            }
        }
    }
    final String[] standaloneMonths = en.getMonths(DateFormatSymbols.STANDALONE, DateFormatSymbols.WIDE);
    fr.setMonths(standaloneMonths, DateFormatSymbols.STANDALONE, DateFormatSymbols.WIDE);
    final String[] standaloneMonths1 = fr.getMonths(DateFormatSymbols.STANDALONE, DateFormatSymbols.WIDE);
    count = standaloneMonths.length;
    if (count != standaloneMonths1.length) {
        errln("ERROR: setMonths(STANDALONE,WIDE) failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!standaloneMonths[i].equals(standaloneMonths1[i])) {
                errln("ERROR: setMonths(STANDALONE,WIDE) failed (different string values)");
            }
        }
    }
    final String[] standaloneShortMonths = en.getMonths(DateFormatSymbols.STANDALONE, DateFormatSymbols.ABBREVIATED);
    fr.setMonths(standaloneShortMonths, DateFormatSymbols.STANDALONE, DateFormatSymbols.ABBREVIATED);
    final String[] standaloneShortMonths1 = fr.getMonths(DateFormatSymbols.STANDALONE, DateFormatSymbols.ABBREVIATED);
    count = standaloneShortMonths.length;
    if (count != standaloneShortMonths1.length) {
        errln("ERROR: setMonths(STANDALONE,ABBREVIATED) failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!standaloneShortMonths[i].equals(standaloneShortMonths1[i])) {
                errln("ERROR: setMonths(STANDALONE,ABBREVIATED) failed (different string values)");
            }
        }
    }
    final String[] standaloneNarrowMonths = en.getMonths(DateFormatSymbols.STANDALONE, DateFormatSymbols.NARROW);
    fr.setMonths(standaloneNarrowMonths, DateFormatSymbols.STANDALONE, DateFormatSymbols.NARROW);
    final String[] standaloneNarrowMonths1 = fr.getMonths(DateFormatSymbols.STANDALONE, DateFormatSymbols.NARROW);
    count = standaloneNarrowMonths.length;
    if (count != standaloneNarrowMonths1.length) {
        errln("ERROR: setMonths(STANDALONE,NARROW) failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!standaloneNarrowMonths[i].equals(standaloneNarrowMonths1[i])) {
                errln("ERROR: setMonths(STANDALONE,NARROW) failed (different string values)");
            }
        }
    }
    final String[] weekdays = en.getWeekdays();
    fr.setWeekdays(weekdays);
    final String[] weekdays1 = fr.getWeekdays();
    count = weekdays.length;
    if (count != weekdays1.length) {
        errln("ERROR: setWeekdays() failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!weekdays[i].equals(weekdays1[i])) {
                errln("ERROR: setWeekdays() failed (different string values)");
            }
        }
    }
    final String[] shortWeekdays = en.getShortWeekdays();
    fr.setShortWeekdays(shortWeekdays);
    final String[] shortWeekdays1 = fr.getShortWeekdays();
    count = shortWeekdays.length;
    if (count != shortWeekdays1.length) {
        errln("ERROR: setShortWeekdays() failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!shortWeekdays[i].equals(shortWeekdays1[i])) {
                errln("ERROR: setShortWeekdays() failed (different string values)");
            }
        }
    }
    final String[] wideWeekdays = en.getWeekdays(DateFormatSymbols.FORMAT, DateFormatSymbols.WIDE);
    fr2.setWeekdays(wideWeekdays, DateFormatSymbols.FORMAT, DateFormatSymbols.WIDE);
    final String[] wideWeekdays1 = fr2.getWeekdays(DateFormatSymbols.FORMAT, DateFormatSymbols.WIDE);
    count = wideWeekdays.length;
    if (count != wideWeekdays1.length) {
        errln("ERROR: setWeekdays(FORMAT,WIDE) failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!wideWeekdays[i].equals(wideWeekdays1[i])) {
                errln("ERROR: setWeekdays(FORMAT,WIDE) failed (different string values)");
            }
        }
    }
    final String[] abbrWeekdays = en.getWeekdays(DateFormatSymbols.FORMAT, DateFormatSymbols.ABBREVIATED);
    final String[] shorterWeekdays = en.getWeekdays(DateFormatSymbols.FORMAT, DateFormatSymbols.SHORT);
    if (!UnicodeStringsArePrefixes(shorterWeekdays, abbrWeekdays)) {
        errln("ERROR: English format short weekday names don't match prefixes of format abbreviated names");
    }
    fr2.setWeekdays(abbrWeekdays, DateFormatSymbols.FORMAT, DateFormatSymbols.ABBREVIATED);
    final String[] abbrWeekdays1 = fr2.getWeekdays(DateFormatSymbols.FORMAT, DateFormatSymbols.ABBREVIATED);
    count = abbrWeekdays.length;
    if (count != abbrWeekdays1.length) {
        errln("ERROR: setWeekdays(FORMAT,ABBREVIATED) failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!abbrWeekdays[i].equals(abbrWeekdays1[i])) {
                errln("ERROR: setWeekdays(FORMAT,ABBREVIATED) failed (different string values)");
            }
        }
    }
    final String[] narrowWeekdays = en.getWeekdays(DateFormatSymbols.FORMAT, DateFormatSymbols.NARROW);
    fr.setWeekdays(narrowWeekdays, DateFormatSymbols.FORMAT, DateFormatSymbols.NARROW);
    final String[] narrowWeekdays1 = fr.getWeekdays(DateFormatSymbols.FORMAT, DateFormatSymbols.NARROW);
    count = narrowWeekdays.length;
    if (count != narrowWeekdays1.length) {
        errln("ERROR: setWeekdays(FORMAT,NARROW) failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!narrowWeekdays[i].equals(narrowWeekdays1[i])) {
                errln("ERROR: setWeekdays(FORMAT,NARROW) failed (different string values)");
            }
        }
    }
    final String[] standaloneWeekdays = en.getWeekdays(DateFormatSymbols.STANDALONE, DateFormatSymbols.WIDE);
    fr.setWeekdays(standaloneWeekdays, DateFormatSymbols.STANDALONE, DateFormatSymbols.WIDE);
    final String[] standaloneWeekdays1 = fr.getWeekdays(DateFormatSymbols.STANDALONE, DateFormatSymbols.WIDE);
    count = standaloneWeekdays.length;
    if (count != standaloneWeekdays1.length) {
        errln("ERROR: setWeekdays(STANDALONE,WIDE) failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!standaloneWeekdays[i].equals(standaloneWeekdays1[i])) {
                errln("ERROR: setWeekdays(STANDALONE,WIDE) failed (different string values)");
            }
        }
    }
    final String[] standaloneShortWeekdays = en.getWeekdays(DateFormatSymbols.STANDALONE, DateFormatSymbols.ABBREVIATED);
    final String[] standaloneShorterWeekdays = en.getWeekdays(DateFormatSymbols.STANDALONE, DateFormatSymbols.SHORT);
    if (!UnicodeStringsArePrefixes(standaloneShorterWeekdays, standaloneShortWeekdays)) {
        errln("ERROR: English standalone short weekday names don't match prefixes of standalone abbreviated names");
    }
    fr.setWeekdays(standaloneShortWeekdays, DateFormatSymbols.STANDALONE, DateFormatSymbols.ABBREVIATED);
    final String[] standaloneShortWeekdays1 = fr.getWeekdays(DateFormatSymbols.STANDALONE, DateFormatSymbols.ABBREVIATED);
    count = standaloneShortWeekdays.length;
    if (count != standaloneShortWeekdays1.length) {
        errln("ERROR: setWeekdays(STANDALONE,ABBREVIATED) failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!standaloneShortWeekdays[i].equals(standaloneShortWeekdays1[i])) {
                errln("ERROR: setWeekdays(STANDALONE,ABBREVIATED) failed (different string values)");
            }
        }
    }
    final String[] standaloneNarrowWeekdays = en.getWeekdays(DateFormatSymbols.STANDALONE, DateFormatSymbols.NARROW);
    fr.setWeekdays(standaloneNarrowWeekdays, DateFormatSymbols.STANDALONE, DateFormatSymbols.NARROW);
    final String[] standaloneNarrowWeekdays1 = fr.getWeekdays(DateFormatSymbols.STANDALONE, DateFormatSymbols.NARROW);
    count = standaloneNarrowWeekdays.length;
    if (count != standaloneNarrowWeekdays1.length) {
        errln("ERROR: setWeekdays(STANDALONE,NARROW) failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!standaloneNarrowWeekdays[i].equals(standaloneNarrowWeekdays1[i])) {
                errln("ERROR: setWeekdays(STANDALONE,NARROW) failed (different string values)");
            }
        }
    }
    final String[] wideQuarters = en.getQuarters(DateFormatSymbols.FORMAT, DateFormatSymbols.WIDE);
    fr2.setQuarters(wideQuarters, DateFormatSymbols.FORMAT, DateFormatSymbols.WIDE);
    final String[] wideQuarters1 = fr2.getQuarters(DateFormatSymbols.FORMAT, DateFormatSymbols.WIDE);
    count = wideQuarters.length;
    if (count != wideQuarters1.length) {
        errln("ERROR: setQuarters(FORMAT, WIDE) failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!wideQuarters[i].equals(wideQuarters1[i])) {
                errln("ERROR: setQuarters(FORMAT, WIDE) failed (different string values)");
            }
        }
    }
    final String[] abbrQuarters = en.getQuarters(DateFormatSymbols.FORMAT, DateFormatSymbols.ABBREVIATED);
    fr2.setQuarters(abbrQuarters, DateFormatSymbols.FORMAT, DateFormatSymbols.ABBREVIATED);
    final String[] abbrQuarters1 = fr2.getQuarters(DateFormatSymbols.FORMAT, DateFormatSymbols.ABBREVIATED);
    count = abbrQuarters.length;
    if (count != abbrQuarters1.length) {
        errln("ERROR: setQuarters(FORMAT, ABBREVIATED) failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!abbrQuarters[i].equals(abbrQuarters1[i])) {
                errln("ERROR: setQuarters(FORMAT, ABBREVIATED) failed (different string values)");
            }
        }
    }
    final String[] standaloneQuarters = en.getQuarters(DateFormatSymbols.STANDALONE, DateFormatSymbols.WIDE);
    fr.setQuarters(standaloneQuarters, DateFormatSymbols.STANDALONE, DateFormatSymbols.WIDE);
    final String[] standaloneQuarters1 = fr.getQuarters(DateFormatSymbols.STANDALONE, DateFormatSymbols.WIDE);
    count = standaloneQuarters.length;
    if (count != standaloneQuarters1.length) {
        errln("ERROR: setQuarters(STANDALONE, WIDE) failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!standaloneQuarters[i].equals(standaloneQuarters1[i])) {
                errln("ERROR: setQuarters(STANDALONE, WIDE) failed (different string values)");
            }
        }
    }
    final String[] standaloneShortQuarters = en.getQuarters(DateFormatSymbols.STANDALONE, DateFormatSymbols.ABBREVIATED);
    fr.setQuarters(standaloneShortQuarters, DateFormatSymbols.STANDALONE, DateFormatSymbols.ABBREVIATED);
    final String[] standaloneShortQuarters1 = fr.getQuarters(DateFormatSymbols.STANDALONE, DateFormatSymbols.ABBREVIATED);
    count = standaloneShortQuarters.length;
    if (count != standaloneShortQuarters1.length) {
        errln("ERROR: setQuarters(STANDALONE, ABBREVIATED) failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!standaloneShortQuarters[i].equals(standaloneShortQuarters1[i])) {
                errln("ERROR: setQuarters(STANDALONE, ABBREVIATED) failed (different string values)");
            }
        }
    }
    final String[] ampms = en.getAmPmStrings();
    fr.setAmPmStrings(ampms);
    final String[] ampms1 = fr.getAmPmStrings();
    count = ampms.length;
    if (count != ampms1.length) {
        errln("ERROR: setAmPmStrings() failed (different size array)");
    } else {
        for (int i = 0; i < count; i++) {
            if (!ampms[i].equals(ampms1[i])) {
                errln("ERROR: setAmPmStrings() failed (different string values)");
            }
        }
    }
    long rowCount = 0, columnCount = 0;
    final String[][] strings = en.getZoneStrings();
    fr.setZoneStrings(strings);
    final String[][] strings1 = fr.getZoneStrings();
    rowCount = strings.length;
    for (int i = 0; i < rowCount; i++) {
        columnCount = strings[i].length;
        for (int j = 0; j < columnCount; j++) {
            if (strings[i][j] != strings1[i][j]) {
                errln("ERROR: setZoneStrings() failed");
            }
        }
    }
    // final String pattern = DateFormatSymbols.getPatternChars();
    // pat1, pat2; //The variable is never used
    String localPattern;
    localPattern = en.getLocalPatternChars();
    fr.setLocalPatternChars(localPattern);
    if (!en.getLocalPatternChars().equals(fr.getLocalPatternChars())) {
        errln("ERROR: setLocalPatternChars() failed");
    }
    // DateFormatSymbols foo = new DateFormatSymbols(); //The variable is never used
    en = (DateFormatSymbols) fr.clone();
    if (!en.equals(fr)) {
        errln("ERROR: Clone failed");
    }
    final String[] shortYearNames = zhChiCal.getYearNames(DateFormatSymbols.FORMAT, DateFormatSymbols.ABBREVIATED);
    final String[] narrowYearNames = zhChiCal.getYearNames(DateFormatSymbols.STANDALONE, DateFormatSymbols.NARROW);
    if (shortYearNames == null || shortYearNames.length != 60 || !shortYearNames[0].equals("\u7532\u5B50") || !shortYearNames[59].equals("\u7678\u4EA5")) {
        errln("ERROR: invalid FORMAT/ABBREVIATED year names from zh@calendar=chinese");
    }
    if (narrowYearNames == null || narrowYearNames.length != 60 || !narrowYearNames[0].equals("\u7532\u5B50") || !narrowYearNames[59].equals("\u7678\u4EA5")) {
        errln("ERROR: invalid STANDALONE/NARROW year names from zh@calendar=chinese");
    }
    final String[] enGregoYearNames = en.getYearNames(DateFormatSymbols.FORMAT, DateFormatSymbols.ABBREVIATED);
    if (enGregoYearNames != null) {
        errln("ERROR: yearNames not null for en");
    }
    final String[] shortZodiacNames = zhChiCal.getZodiacNames(DateFormatSymbols.FORMAT, DateFormatSymbols.ABBREVIATED);
    if (shortZodiacNames == null || shortZodiacNames.length != 12 || !shortZodiacNames[0].equals("\u9F20") || !shortZodiacNames[11].equals("\u732A")) {
        errln("ERROR: invalid FORMAT/ABBREVIATED zodiac names from zh@calendar=chinese");
    }
    final String[] newZodiacNames = { "Rat", "Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig" };
    zhChiCal.setZodiacNames(newZodiacNames, DateFormatSymbols.FORMAT, DateFormatSymbols.ABBREVIATED);
    final String[] testZodiacNames = zhChiCal.getZodiacNames(DateFormatSymbols.FORMAT, DateFormatSymbols.ABBREVIATED);
    if (testZodiacNames == null || testZodiacNames.length != 12 || !testZodiacNames[0].equals("Rat") || !testZodiacNames[11].equals("Pig")) {
        errln("ERROR: setZodiacNames then getZodiacNames not working for zh@calendar=chinese");
    }
    String leapMonthPatternFmtAbbrev = zhChiCal.getLeapMonthPattern(DateFormatSymbols.FORMAT, DateFormatSymbols.ABBREVIATED);
    if (leapMonthPatternFmtAbbrev == null || !leapMonthPatternFmtAbbrev.equals("\u95F0{0}")) {
        errln("ERROR: invalid FORMAT/ABBREVIATED leapMonthPattern from zh@calendar=chinese");
    }
}
Also used : ULocale(android.icu.util.ULocale) DateFormatSymbols(android.icu.text.DateFormatSymbols) Test(org.junit.Test)

Example 13 with DateFormatSymbols

use of android.icu.text.DateFormatSymbols in project j2objc by google.

the class IntlTestDateFormatSymbols method TestGetWeekdays2.

@Test
public void TestGetWeekdays2() {
    DateFormatSymbols symbol;
    symbol = new DateFormatSymbols(Locale.getDefault());
    int[] context = { DateFormatSymbols.STANDALONE, DateFormatSymbols.FORMAT };
    int[] width = { DateFormatSymbols.WIDE, DateFormatSymbols.ABBREVIATED, DateFormatSymbols.NARROW };
    for (int i = 0; i < context.length; i++) {
        for (int j = 0; j < width.length; j++) {
            String[] wd = symbol.getWeekdays(context[i], width[j]);
            int cnt = wd.length;
            logln("size = " + cnt);
            for (int k = 0; k < wd.length; k++) {
                logln(wd[k]);
            }
        }
    }
}
Also used : DateFormatSymbols(android.icu.text.DateFormatSymbols) Test(org.junit.Test)

Example 14 with DateFormatSymbols

use of android.icu.text.DateFormatSymbols in project j2objc by google.

the class IntlTestDateFormatSymbols method TestGetMonths2.

@Test
public void TestGetMonths2() {
    DateFormatSymbols symbol;
    symbol = new DateFormatSymbols(Locale.getDefault());
    int[] context = { DateFormatSymbols.STANDALONE, DateFormatSymbols.FORMAT };
    int[] width = { DateFormatSymbols.WIDE, DateFormatSymbols.ABBREVIATED, DateFormatSymbols.NARROW };
    for (int i = 0; i < context.length; i++) {
        for (int j = 0; j < width.length; j++) {
            String[] month = symbol.getMonths(context[i], width[j]);
            int cnt = month.length;
            logln("size = " + cnt);
            for (int k = 0; k < month.length; k++) {
                logln(month[k]);
            }
        }
    }
}
Also used : DateFormatSymbols(android.icu.text.DateFormatSymbols) Test(org.junit.Test)

Example 15 with DateFormatSymbols

use of android.icu.text.DateFormatSymbols in project j2objc by google.

the class IntlTestSimpleDateFormatAPI method TestAPI.

// This test checks various generic API methods in DecimalFormat to achieve 100% API coverage.
@Test
public void TestAPI() {
    logln("SimpleDateFormat API test---");
    logln("");
    Locale.setDefault(Locale.ENGLISH);
    // ======= Test constructors
    logln("Testing SimpleDateFormat constructors");
    SimpleDateFormat def = new SimpleDateFormat();
    final String pattern = new String("yyyy.MM.dd G 'at' hh:mm:ss z");
    SimpleDateFormat pat = new SimpleDateFormat(pattern);
    SimpleDateFormat pat_fr = new SimpleDateFormat(pattern, Locale.FRENCH);
    DateFormatSymbols symbols = new DateFormatSymbols(Locale.FRENCH);
    SimpleDateFormat cust1 = new SimpleDateFormat(pattern, symbols);
    // ======= Test clone() and equality
    logln("Testing clone(), assignment and equality operators");
    Format clone = (Format) def.clone();
    if (!clone.equals(def)) {
        errln("ERROR: Format clone or equals failed");
    }
    // ======= Test various format() methods
    logln("Testing various format() methods");
    Date d = new Date((long) 837039928046.0);
    StringBuffer res1 = new StringBuffer();
    StringBuffer res2 = new StringBuffer();
    FieldPosition pos1 = new FieldPosition(0);
    FieldPosition pos2 = new FieldPosition(0);
    res1 = def.format(d, res1, pos1);
    logln("" + d.getTime() + " formatted to " + res1);
    res2 = cust1.format(d, res2, pos2);
    logln("" + d.getTime() + " formatted to " + res2);
    // ======= Test parse()
    logln("Testing parse()");
    String text = new String("02/03/76, 2:50 AM, CST");
    Date result1 = new Date();
    Date result2 = new Date();
    ParsePosition pos = new ParsePosition(0);
    result1 = def.parse(text, pos);
    logln(text + " parsed into " + result1);
    try {
        result2 = def.parse(text);
    } catch (ParseException e) {
        errln("ERROR: parse() failed");
    }
    logln(text + " parsed into " + result2);
    // ======= Test getters and setters
    logln("Testing getters and setters");
    final DateFormatSymbols syms = pat.getDateFormatSymbols();
    def.setDateFormatSymbols(syms);
    pat_fr.setDateFormatSymbols(syms);
    if (!pat.getDateFormatSymbols().equals(def.getDateFormatSymbols())) {
        errln("ERROR: set DateFormatSymbols() failed");
    }
    /*
        DateFormatSymbols has not the method getTwoDigitStartDate();
        //Date startDate = null; //The variable is never used
        try {
//            startDate = pat.getTwoDigitStartDate();
        }
        catch (Exception e) {
            errln("ERROR: getTwoDigitStartDate() failed");
        }

        try {
//            pat_fr.setTwoDigitStartDate(startDate);
        }
        catch (Exception e) {
            errln("ERROR: setTwoDigitStartDate() failed");
        }*/
    // ======= Test applyPattern()
    logln("Testing applyPattern()");
    String p1 = new String("yyyy.MM.dd G 'at' hh:mm:ss z");
    logln("Applying pattern " + p1);
    pat.applyPattern(p1);
    String s2 = pat.toPattern();
    logln("Extracted pattern is " + s2);
    if (!s2.equals(p1)) {
        errln("ERROR: toPattern() result did not match pattern applied");
    }
    logln("Applying pattern " + p1);
    pat.applyLocalizedPattern(p1);
    String s3 = pat.toLocalizedPattern();
    logln("Extracted pattern is " + s3);
    if (!s3.equals(p1)) {
        errln("ERROR: toLocalizedPattern() result did not match pattern applied");
    }
    // ======= Test for Ticket 5684 (Parsing patterns with 'Y' and 'e'
    logln("Testing parse()");
    String p2 = new String("YYYY'W'wwe");
    logln("Applying pattern " + p2);
    pat.applyPattern(p2);
    Date dt = pat.parse("2007W014", new ParsePosition(0));
    if (dt == null) {
        errln("ERROR: Parsing failed using 'Y' and 'e'");
    }
// ======= Test getStaticClassID()
// logln("Testing instanceof");
// try {
// DateFormat test = new SimpleDateFormat();
// if (! (test instanceof SimpleDateFormat)) {
// errln("ERROR: instanceof failed");
// }
// }
// catch (Exception e) {
// errln("ERROR: Couldn't create a SimpleDateFormat");
// }
}
Also used : Format(java.text.Format) SimpleDateFormat(android.icu.text.SimpleDateFormat) DateFormatSymbols(android.icu.text.DateFormatSymbols) ParseException(java.text.ParseException) FieldPosition(java.text.FieldPosition) SimpleDateFormat(android.icu.text.SimpleDateFormat) Date(java.util.Date) ParsePosition(java.text.ParsePosition) Test(org.junit.Test)

Aggregations

DateFormatSymbols (android.icu.text.DateFormatSymbols)17 Test (org.junit.Test)14 ULocale (android.icu.util.ULocale)7 SimpleDateFormat (android.icu.text.SimpleDateFormat)6 Calendar (android.icu.util.Calendar)5 Date (java.util.Date)5 ChineseDateFormatSymbols (android.icu.text.ChineseDateFormatSymbols)4 BuddhistCalendar (android.icu.util.BuddhistCalendar)4 ChineseCalendar (android.icu.util.ChineseCalendar)4 GregorianCalendar (android.icu.util.GregorianCalendar)4 JapaneseCalendar (android.icu.util.JapaneseCalendar)4 FieldPosition (java.text.FieldPosition)4 ParseException (java.text.ParseException)4 Locale (java.util.Locale)4 ChineseDateFormat (android.icu.text.ChineseDateFormat)3 DateFormat (android.icu.text.DateFormat)3 HebrewCalendar (android.icu.util.HebrewCalendar)3 IslamicCalendar (android.icu.util.IslamicCalendar)3 IOException (java.io.IOException)3 TimeZone (android.icu.util.TimeZone)2