Improve handling of unknown timezone definitions (should fix #333)

pull/2/head
rfc2822 10 years ago
parent 6f0b9421c1
commit c8da282db0

@ -352,15 +352,17 @@ public class Event extends Resource {
date.setTimeZone(tzRegistry.getTimeZone(localTZ));
}
public static String TimezoneDefToTzId(String timezoneDef) {
public static String TimezoneDefToTzId(String timezoneDef) throws IllegalArgumentException {
try {
CalendarBuilder builder = new CalendarBuilder();
net.fortuna.ical4j.model.Calendar cal = builder.build(new StringReader(timezoneDef));
VTimeZone timezone = (VTimeZone)cal.getComponent(VTimeZone.VTIMEZONE);
return timezone.getTimeZoneId().getValue();
if (timezoneDef != null) {
CalendarBuilder builder = new CalendarBuilder();
net.fortuna.ical4j.model.Calendar cal = builder.build(new StringReader(timezoneDef));
VTimeZone timezone = (VTimeZone)cal.getComponent(VTimeZone.VTIMEZONE);
return timezone.getTimeZoneId().getValue();
}
} catch (Exception ex) {
Log.w(TAG, "Can't understand time zone definition", ex);
}
return null;
throw new IllegalArgumentException();
}
}

@ -536,7 +536,10 @@ public class WebDavResource {
properties.put(Property.COLOR, prop.calendarColor.getColor());
if (prop.calendarTimezone != null)
properties.put(Property.TIMEZONE, Event.TimezoneDefToTzId(prop.calendarTimezone.getTimezone()));
try {
properties.put(Property.TIMEZONE, Event.TimezoneDefToTzId(prop.calendarTimezone.getTimezone()));
} catch(IllegalArgumentException e) {
}
if (prop.supportedCalendarComponentSet != null) {
supportedComponents = new LinkedList<String>();

@ -73,6 +73,47 @@ public class EventTest extends InstrumentationTestCase {
assertEquals(Time.TIMEZONE_UTC, eAllDay0Sec.getDtEndTzID());
}
public void testTimezoneDefToTzId() {
final String VTIMEZONE_SAMPLE = // taken from RFC 4791, 5.2.2. CALDAV:calendar-timezone Property
"BEGIN:VCALENDAR\n" +
"PRODID:-//Example Corp.//CalDAV Client//EN\n" +
"VERSION:2.0\n" +
"BEGIN:VTIMEZONE\n" +
"TZID:US-Eastern\n" +
"LAST-MODIFIED:19870101T000000Z\n" +
"BEGIN:STANDARD\n" +
"DTSTART:19671029T020000\n" +
"RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10\n" +
"TZOFFSETFROM:-0400\n" +
"TZOFFSETTO:-0500\n" +
"TZNAME:Eastern Standard Time (US &amp; Canada)\n" +
"END:STANDARD\n" +
"BEGIN:DAYLIGHT\n" +
"DTSTART:19870405T020000\n" +
"RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4\n" +
"TZOFFSETFROM:-0500\n" +
"TZOFFSETTO:-0400\n" +
"TZNAME:Eastern Daylight Time (US &amp; Canada)\n" +
"END:DAYLIGHT\n" +
"END:VTIMEZONE\n" +
"END:VCALENDAR";
assertEquals("US-Eastern", Event.TimezoneDefToTzId(VTIMEZONE_SAMPLE));
try {
Event.TimezoneDefToTzId(null);
fail();
} catch(IllegalArgumentException e) {
assert(true);
}
try {
Event.TimezoneDefToTzId("/* invalid content */");
fail();
} catch(IllegalArgumentException e) {
assert(true);
}
}
protected Event parseCalendar(String fname) throws IOException, InvalidResourceException {
@Cleanup InputStream in = assetMgr.open(fname, AssetManager.ACCESS_STREAMING);

Loading…
Cancel
Save