Fix: Support events without end

According to RFC5545, an event may have no DTEND nor DURATION property. Set end = start in that case.
pull/30/head
dlichtistw 2018-09-30 12:28:41 +02:00
rodzic b862633fd7
commit 24e1bb0ef7
3 zmienionych plików z 18 dodań i 7 usunięć

Wyświetl plik

@ -97,8 +97,6 @@ class Event:
:param uid: UID of new event
:return: new event
"""
duration = self.end - self.start
if not new_start:
new_start = self.start
@ -109,7 +107,11 @@ class Event:
ne.summary = self.summary
ne.description = self.description
ne.start = new_start
if self.end:
duration = self.end - self.start
ne.end = (new_start + duration)
ne.all_day = (self.all_day and (new_start - self.start).seconds == 0)
ne.uid = uid
@ -131,10 +133,10 @@ def create_event(component, tz=UTC):
if component.get('dtend'):
event.end = normalize(component.get('dtend').dt, tz=tz)
elif component.get('duration'):
elif component.get('duration'): # compute implicit end as start + duration
event.end = event.start + component.get('duration').dt
else:
raise ValueError("Event has neither end, nor duration property.")
else: # compute implicit end as start + 0
event.end = event.start
event.summary = str(component.get('summary'))
event.description = str(component.get('description'))

Wyświetl plik

@ -6,9 +6,14 @@ DESCRIPTION:Event with duration (1 day), instead of explicit end.
SUMMARY:Duration Event
END:VEVENT
BEGIN:VEVENT
DTSTART:20180120T100000
DTSTART:20180115T100000
DURATION:PT1H
DESCRIPTION:Event with duration (1 hour), instead of explicit end.
SUMMARY:Duration Event
END:VEVENT
BEGIN:VEVENT
DTSTART:20180120T120000
DESCRIPTION:Event without explicit dtend, nor duration property.
SUMMARY:Short event
END:VEVENT
END:VCALENDAR

Wyświetl plik

@ -46,6 +46,10 @@ class ICalEventsTests(unittest.TestCase):
self.assertEqual(e2.start.hour, 10, "explicit event start")
self.assertEqual(e2.end.hour, 11, "implicit event end")
e3 = evs[2]
self.assertEqual(e3.start.hour, 12, "explicit event start")
self.assertEqual(e3.end.hour, 12, "implicit event end")
def test_events_recurring(self):
ical = "test/test_data/recurring.ics"
start = date(2018, 10, 15)