Search in sources :

Example 11 with VTimeZone

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

the class TimeZoneRuleTest method TestVTimeZoneParse.

@Test
public void TestVTimeZoneParse() {
    // Trying to create VTimeZone from empty data
    StringReader r = new StringReader("");
    VTimeZone empty = VTimeZone.create(r);
    if (empty != null) {
        errln("FAIL: Non-null VTimeZone is returned for empty VTIMEZONE data");
    }
    // Create VTimeZone for Asia/Tokyo
    String asiaTokyo = "BEGIN:VTIMEZONE\r\n" + "TZID:Asia\r\n" + "\t/Tokyo\r\n" + "BEGIN:STANDARD\r\n" + "TZOFFSETFROM:+0900\r\n" + "TZOFFSETTO:+0900\r\n" + "TZNAME:JST\r\n" + "DTSTART:19700101\r\n" + " T000000\r\n" + "END:STANDARD\r\n" + "END:VTIMEZONE";
    r = new StringReader(asiaTokyo);
    VTimeZone tokyo = VTimeZone.create(r);
    if (tokyo == null) {
        errln("FAIL: Failed to create a VTimeZone tokyo");
    } else {
        // Make sure offsets are correct
        int[] offsets = new int[2];
        tokyo.getOffset(System.currentTimeMillis(), false, offsets);
        if (offsets[0] != 9 * HOUR || offsets[1] != 0) {
            errln("FAIL: Bad offsets returned by a VTimeZone created for Tokyo");
        }
    }
    // Create VTimeZone from VTIMEZONE data
    String fooData = "BEGIN:VCALENDAR\r\n" + "BEGIN:VTIMEZONE\r\n" + "TZID:FOO\r\n" + "BEGIN:STANDARD\r\n" + "TZOFFSETFROM:-0700\r\n" + "TZOFFSETTO:-0800\r\n" + "TZNAME:FST\r\n" + "DTSTART:20071010T010000\r\n" + "RRULE:FREQ=YEARLY;BYDAY=WE;BYMONTHDAY=10,11,12,13,14,15,16;BYMONTH=10\r\n" + "END:STANDARD\r\n" + "BEGIN:DAYLIGHT\r\n" + "TZOFFSETFROM:-0800\r\n" + "TZOFFSETTO:-0700\r\n" + "TZNAME:FDT\r\n" + "DTSTART:20070415T010000\r\n" + "RRULE:FREQ=YEARLY;BYMONTHDAY=15;BYMONTH=4\r\n" + "END:DAYLIGHT\r\n" + "END:VTIMEZONE\r\n" + "END:VCALENDAR";
    r = new StringReader(fooData);
    VTimeZone foo = VTimeZone.create(r);
    if (foo == null) {
        errln("FAIL: Failed to create a VTimeZone foo");
    } else {
        // Write VTIMEZONE data
        StringWriter w = new StringWriter();
        try {
            foo.write(w, getUTCMillis(2005, Calendar.JANUARY, 1));
        } catch (IOException ioe) {
            errln("FAIL: IOException is thrown while writing VTIMEZONE data for foo");
        }
        logln(w.toString());
    }
}
Also used : StringWriter(java.io.StringWriter) VTimeZone(android.icu.util.VTimeZone) StringReader(java.io.StringReader) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

VTimeZone (android.icu.util.VTimeZone)11 Test (org.junit.Test)9 BasicTimeZone (android.icu.util.BasicTimeZone)6 IOException (java.io.IOException)6 Date (java.util.Date)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 InputStreamReader (java.io.InputStreamReader)4 OutputStreamWriter (java.io.OutputStreamWriter)4 JavaTimeZone (android.icu.impl.JavaTimeZone)3 RuleBasedTimeZone (android.icu.util.RuleBasedTimeZone)3 SimpleTimeZone (android.icu.util.SimpleTimeZone)3 TimeArrayTimeZoneRule (android.icu.util.TimeArrayTimeZoneRule)3 TimeZone (android.icu.util.TimeZone)3 TimeZoneTransition (android.icu.util.TimeZoneTransition)3 NativeTimeZone (com.google.j2objc.util.NativeTimeZone)3 StringReader (java.io.StringReader)2 AnnualTimeZoneRule (android.icu.util.AnnualTimeZoneRule)1 Calendar (android.icu.util.Calendar)1 GregorianCalendar (android.icu.util.GregorianCalendar)1