Search in sources :

Example 11 with DateInterval

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

the class DateIntervalFormatTest method expect.

private void expect(String[] data, int data_length) {
    int i = 1;
    while (i < data_length) {
        String locName = data[i++];
        ULocale loc = new ULocale(locName);
        SimpleDateFormat ref = new SimpleDateFormat(data[0], loc);
        // 'f'
        String datestr = data[i++];
        String datestr_2 = data[i++];
        Date date, date_2;
        try {
            date = ref.parse(datestr);
            date_2 = ref.parse(datestr_2);
        } catch (ParseException e) {
            errln("parse exception" + e);
            continue;
        }
        DateInterval dtitv = new DateInterval(date.getTime(), date_2.getTime());
        String oneSkeleton = data[i++];
        DateIntervalFormat dtitvfmt = DateIntervalFormat.getInstance(oneSkeleton, loc);
        String expected = data[i++];
        String formatted = dtitvfmt.format(dtitv);
        if (!formatted.equals(Utility.unescape(expected))) {
            errln("\"" + locName + "\\" + oneSkeleton + "\\" + datestr + "\\" + datestr_2 + "\"\t expected: " + expected + "\tgot: " + formatted + "\n");
        }
    }
}
Also used : ULocale(android.icu.util.ULocale) DateIntervalFormat(android.icu.text.DateIntervalFormat) ParseException(java.text.ParseException) DateInterval(android.icu.util.DateInterval) SimpleDateFormat(android.icu.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

DateIntervalFormat (android.icu.text.DateIntervalFormat)11 DateInterval (android.icu.util.DateInterval)11 ULocale (android.icu.util.ULocale)7 Test (org.junit.Test)7 DateIntervalInfo (android.icu.text.DateIntervalInfo)6 Calendar (android.icu.util.Calendar)6 SimpleDateFormat (android.icu.text.SimpleDateFormat)5 FieldPosition (java.text.FieldPosition)5 ParseException (java.text.ParseException)5 Date (java.util.Date)4 TimeZone (android.icu.util.TimeZone)3 DateFormat (android.icu.text.DateFormat)2 PatternInfo (android.icu.text.DateIntervalInfo.PatternInfo)1 Output (android.icu.util.Output)1 ParsePosition (java.text.ParsePosition)1 ArrayList (java.util.ArrayList)1