mirror of
https://github.com/etesync/android
synced 2025-06-23 16:38:51 +00:00
Improve handling of unknown timezone definitions (should fix #333)
This commit is contained in:
parent
6f0b9421c1
commit
c8da282db0
@ -352,15 +352,17 @@ public class Event extends Resource {
|
|||||||
date.setTimeZone(tzRegistry.getTimeZone(localTZ));
|
date.setTimeZone(tzRegistry.getTimeZone(localTZ));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String TimezoneDefToTzId(String timezoneDef) {
|
public static String TimezoneDefToTzId(String timezoneDef) throws IllegalArgumentException {
|
||||||
try {
|
try {
|
||||||
|
if (timezoneDef != null) {
|
||||||
CalendarBuilder builder = new CalendarBuilder();
|
CalendarBuilder builder = new CalendarBuilder();
|
||||||
net.fortuna.ical4j.model.Calendar cal = builder.build(new StringReader(timezoneDef));
|
net.fortuna.ical4j.model.Calendar cal = builder.build(new StringReader(timezoneDef));
|
||||||
VTimeZone timezone = (VTimeZone)cal.getComponent(VTimeZone.VTIMEZONE);
|
VTimeZone timezone = (VTimeZone)cal.getComponent(VTimeZone.VTIMEZONE);
|
||||||
return timezone.getTimeZoneId().getValue();
|
return timezone.getTimeZoneId().getValue();
|
||||||
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Log.w(TAG, "Can't understand time zone definition", 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());
|
properties.put(Property.COLOR, prop.calendarColor.getColor());
|
||||||
|
|
||||||
if (prop.calendarTimezone != null)
|
if (prop.calendarTimezone != null)
|
||||||
|
try {
|
||||||
properties.put(Property.TIMEZONE, Event.TimezoneDefToTzId(prop.calendarTimezone.getTimezone()));
|
properties.put(Property.TIMEZONE, Event.TimezoneDefToTzId(prop.calendarTimezone.getTimezone()));
|
||||||
|
} catch(IllegalArgumentException e) {
|
||||||
|
}
|
||||||
|
|
||||||
if (prop.supportedCalendarComponentSet != null) {
|
if (prop.supportedCalendarComponentSet != null) {
|
||||||
supportedComponents = new LinkedList<String>();
|
supportedComponents = new LinkedList<String>();
|
||||||
|
@ -73,6 +73,47 @@ public class EventTest extends InstrumentationTestCase {
|
|||||||
assertEquals(Time.TIMEZONE_UTC, eAllDay0Sec.getDtEndTzID());
|
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 & 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 & 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 {
|
protected Event parseCalendar(String fname) throws IOException, InvalidResourceException {
|
||||||
@Cleanup InputStream in = assetMgr.open(fname, AssetManager.ACCESS_STREAMING);
|
@Cleanup InputStream in = assetMgr.open(fname, AssetManager.ACCESS_STREAMING);
|
||||||
|
Loading…
Reference in New Issue
Block a user