Search in sources :

Example 6 with TimeType

use of android.icu.text.TimeZoneFormat.TimeType in project j2objc by google.

the class TimeZoneFormatTest method TestFormatTZDBNames.

@Test
public void TestFormatTZDBNames() {
    // 2013-01-15T00:00:00Z
    final Date dateJan = new Date(1358208000000L);
    // 2013-07-15T00:00:00Z
    final Date dateJul = new Date(1373846400000L);
    final Object[][] TESTDATA = { { "en", "America/Chicago", dateJan, Style.SPECIFIC_SHORT, "CST", TimeType.STANDARD }, { "en", "Asia/Shanghai", dateJan, Style.SPECIFIC_SHORT, "CST", TimeType.STANDARD }, { "zh_Hans", "Asia/Shanghai", dateJan, Style.SPECIFIC_SHORT, "CST", TimeType.STANDARD }, { "en", "America/Los_Angeles", dateJul, Style.SPECIFIC_LONG, // No long display names
    "GMT-07:00", TimeType.DAYLIGHT }, { "ja", "America/Los_Angeles", dateJul, Style.SPECIFIC_SHORT, "PDT", TimeType.DAYLIGHT }, { "en", "Australia/Sydney", dateJan, Style.SPECIFIC_SHORT, "AEDT", TimeType.DAYLIGHT }, { "en", "Australia/Sydney", dateJul, Style.SPECIFIC_SHORT, "AEST", TimeType.STANDARD } };
    for (Object[] testCase : TESTDATA) {
        ULocale loc = new ULocale((String) testCase[0]);
        TimeZoneFormat tzfmt = TimeZoneFormat.getInstance(loc).cloneAsThawed();
        TimeZoneNames tzdbNames = TimeZoneNames.getTZDBInstance(loc);
        tzfmt.setTimeZoneNames(tzdbNames);
        TimeZone tz = TimeZone.getTimeZone((String) testCase[1]);
        Output<TimeType> timeType = new Output<TimeType>();
        String out = tzfmt.format((Style) testCase[3], tz, ((Date) testCase[2]).getTime(), timeType);
        if (!out.equals(testCase[4]) || timeType.value != testCase[5]) {
            errln("Format result for [locale=" + testCase[0] + ",tzid=" + testCase[1] + ",date=" + testCase[2] + ",style=" + testCase[3] + "]: expected [output=" + testCase[4] + ",type=" + testCase[5] + "]; actual [output=" + out + ",type=" + timeType.value + "]");
        }
    }
}
Also used : SimpleTimeZone(android.icu.util.SimpleTimeZone) TimeZone(android.icu.util.TimeZone) BasicTimeZone(android.icu.util.BasicTimeZone) ULocale(android.icu.util.ULocale) Output(android.icu.util.Output) TZDBTimeZoneNames(android.icu.impl.TZDBTimeZoneNames) TimeZoneNames(android.icu.text.TimeZoneNames) TimeZoneFormat(android.icu.text.TimeZoneFormat) Date(java.util.Date) TimeType(android.icu.text.TimeZoneFormat.TimeType) Test(org.junit.Test)

Aggregations

TimeType (android.icu.text.TimeZoneFormat.TimeType)6 TimeZoneFormat (android.icu.text.TimeZoneFormat)4 BasicTimeZone (android.icu.util.BasicTimeZone)4 Output (android.icu.util.Output)4 TimeZone (android.icu.util.TimeZone)4 SimpleTimeZone (android.icu.util.SimpleTimeZone)3 ULocale (android.icu.util.ULocale)3 Date (java.util.Date)3 Test (org.junit.Test)3 Style (android.icu.text.TimeZoneFormat.Style)2 TimeZoneNames (android.icu.text.TimeZoneNames)2 DayPeriodRules (android.icu.impl.DayPeriodRules)1 TZDBTimeZoneNames (android.icu.impl.TZDBTimeZoneNames)1 ParseOption (android.icu.text.TimeZoneFormat.ParseOption)1 NameType (android.icu.text.TimeZoneNames.NameType)1 Calendar (android.icu.util.Calendar)1 HebrewCalendar (android.icu.util.HebrewCalendar)1 TimeZoneTransition (android.icu.util.TimeZoneTransition)1 AttributedString (java.text.AttributedString)1 ParsePosition (java.text.ParsePosition)1