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());
}
}
Aggregations