Commit be1e1e9b authored by Ricki Hirner's avatar Ricki Hirner

Handle events with zero duration correctly (convert to all-day event)

parent 2f6a94e8
Pipeline #7765078 passed with stage
in 7 minutes and 32 seconds
......@@ -33,6 +33,7 @@ import net.fortuna.ical4j.model.parameter.Value;
import net.fortuna.ical4j.model.property.Attendee;
import net.fortuna.ical4j.model.property.DtEnd;
import net.fortuna.ical4j.model.property.DtStart;
import net.fortuna.ical4j.model.property.Duration;
import net.fortuna.ical4j.model.property.ExDate;
import net.fortuna.ical4j.model.property.Organizer;
import net.fortuna.ical4j.model.property.RRule;
......@@ -248,7 +249,7 @@ public class AndroidEventTest extends InstrumentationTestCase {
}
}
public void testBuildAllDayEntry() throws ParseException, FileNotFoundException, CalendarStorageException {
public void testAllDay() throws ParseException, FileNotFoundException, CalendarStorageException {
// add all-day event to calendar provider
Event event = new Event();
event.summary = "All-day event";
......@@ -272,6 +273,24 @@ public class AndroidEventTest extends InstrumentationTestCase {
assertTrue(event2.isAllDay());
}
public void testAllDayWithoutDuration() throws ParseException, FileNotFoundException, CalendarStorageException {
// add all-day event with 0 sec duration to calendar provider
Event event = new Event();
event.summary = "Event without duration";
event.dtStart = new DtStart(new Date("20150501"));
event.duration = new Duration(new Dur("PT0S"));
Uri uri = new TestEvent(calendar, event).add();
assertNotNull("Couldn't add event", uri);
// read again and verify result
@Cleanup("delete") TestEvent testEvent = new TestEvent(calendar, ContentUris.parseId(uri));
Event event2 = testEvent.getEvent();
// should now be an all-day event (converted by ical4android because events without duration don't show up in Android calendar)
assertEquals(event.dtStart, event2.dtStart);
assertEquals(event.dtStart.getDate().getTime() + 86400000, event2.dtEnd.getDate().getTime());
assertTrue(event2.isAllDay());
}
public void testNoOrganizerWithoutAttendees() throws ParseException, URISyntaxException, CalendarStorageException, FileNotFoundException {
Event event = new Event();
event.summary = "Not a group-scheduled event";
......@@ -311,4 +330,23 @@ public class AndroidEventTest extends InstrumentationTestCase {
assertNull(testEvent.getEvent().dtEnd);
}
public void testWithoutDuration() throws ParseException, FileNotFoundException, CalendarStorageException {
// add event with 0 sec duration to calendar provider
Event event = new Event();
event.summary = "Event without duration";
event.dtStart = new DtStart(new Date("20150501T152010Z"));
event.duration = new Duration(new Dur("PT0S"));
Uri uri = new TestEvent(calendar, event).add();
assertNotNull("Couldn't add event", uri);
// read again and verify result
@Cleanup("delete") TestEvent testEvent = new TestEvent(calendar, ContentUris.parseId(uri));
Event event2 = testEvent.getEvent();
// should now be an all-day event (converted by ical4android because events without duration don't show up in Android calendar)
assertEquals(event.dtStart, event2.dtStart);
assertEquals(event.dtStart.getDate().getTime() + 86400000, event2.dtEnd.getDate().getTime());
assertTrue(event2.isAllDay());
}
}
......@@ -530,6 +530,7 @@ public abstract class AndroidEvent {
c.setTime(event.dtStart.getDate());
c.add(java.util.Calendar.DATE, 1);
event.dtEnd = new DtEnd(new Date(c.getTimeInMillis()));
event.duration = null;
}
/* For cases where a "VEVENT" calendar component
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment