summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2014-03-04 13:58:53 -0500
committerThomas Bruederli <bruederli@kolabsys.com>2014-03-04 13:58:53 -0500
commit74c17bde3f0eb6d83730d3711c8b9d8f68c6c2dc (patch)
tree8a0fb1dfa07437956467e6220aef9efeb097debc
parent14a14d77a1178167614ad3bcac9e9dfe4d6e0372 (diff)
downloadpykolab-74c17bde3f0eb6d83730d3711c8b9d8f68c6c2dc.tar.gz
Import DURATION and EXDATE properties from ical
-rw-r--r--pykolab/xml/event.py33
-rw-r--r--tests/unit/test-003-event.py12
2 files changed, 41 insertions, 4 deletions
diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py
index afaa088..181c270 100644
--- a/pykolab/xml/event.py
+++ b/pykolab/xml/event.py
@@ -183,12 +183,13 @@ class Event(object):
if ical_event.has_key(attr):
self.set_from_ical(attr.lower(), ical_event[attr])
- # HACK: use libkolab::EventCal::fromICal() to parse RRULEs
+ # HACK: use calendaring::EventCal::fromICal() to parse RRULEs
if ical_event.has_key('RRULE'):
from kolab.calendaring import EventCal
event_xml = EventCal()
event_xml.fromICal("BEGIN:VCALENDAR\nVERSION:2.0\n" + ical + "\nEND:VCALENDAR")
self.event.setRecurrenceRule(event_xml.recurrenceRule())
+ self.event.setExceptionDates(event_xml.exceptionDates())
def get_attendee_participant_status(self, attendee):
return attendee.get_participant_status()
@@ -242,11 +243,30 @@ class Event(object):
def get_description(self):
return self.event.description()
+ def get_duration(self):
+ duration = self.event.duration()
+ if duration and duration.isValid():
+ dtd = datetime.timedelta(
+ days=duration.days(),
+ seconds=duration.seconds(),
+ minutes=duration.minutes(),
+ hours=duration.hours(),
+ weeks=duration.weeks()
+ )
+ return dtd
+
+ return None
+
def get_end(self):
- return xmlutils.from_cdatetime(self.event.end(), True)
+ dt = xmlutils.from_cdatetime(self.event.end(), True)
+ if not dt:
+ duration = self.get_duration()
+ if duration is not None:
+ dt = self.get_start() + duration
+ return dt
def get_exception_dates(self):
- return self.event.exceptionDates()
+ return map(lambda _: xmlutils.from_cdatetime(_, True), self.event.exceptionDates())
def get_ical_attendee(self):
# TODO: Formatting, aye? See also the example snippet:
@@ -462,6 +482,8 @@ class Event(object):
self.set_ical_dtend(value.dt)
elif attr == "dtstart":
self.set_ical_dtstart(value.dt)
+ elif attr == "duration":
+ self.set_ical_duration(value)
elif attr == "status":
self.set_ical_status(value)
elif attr == "summary":
@@ -526,6 +548,11 @@ class Event(object):
def set_ical_dtstart(self, dtstart):
self.set_start(dtstart)
+ def set_ical_duration(self, value):
+ if value.dt:
+ duration = kolabformat.Duration(value.dt.days, 0, 0, value.dt.seconds, False)
+ self.event.setDuration(duration)
+
def set_ical_organizer(self, organizer):
address = str(organizer).split(':')[-1]
diff --git a/tests/unit/test-003-event.py b/tests/unit/test-003-event.py
index f9fcf8b..3f9083e 100644
--- a/tests/unit/test-003-event.py
+++ b/tests/unit/test-003-event.py
@@ -117,10 +117,14 @@ class TestEventXML(unittest.TestCase):
def test_018_load_from_ical(self):
ical_str = """BEGIN:VCALENDAR
VERSION:2.0
+PRODID:-//Apple Inc.//Mac OS X 10.9.2//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTART;TZID=Europe/Zurich;VALUE=DATE-TIME:20140523T110000
-DTEND;TZID=Europe/Zurich;VALUE=DATE-TIME:20140523T130000
+DURATION:PT1H30M0S
+RRULE:FREQ=WEEKLY;INTERVAL=1;COUNT=10
+EXDATE;TZID=Europe/Zurich;VALUE=DATE-TIME:20140530T110000
+EXDATE;TZID=Europe/Zurich;VALUE=DATE-TIME:20140620T110000
UID:7a35527d-f783-4b58-b404-b1389bd2fc57
ATTENDEE;CN="Doe, Jane";CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED
;ROLE=REQ-PARTICIPANT;RSVP=FALSE:MAILTO:jane@doe.org
@@ -134,6 +138,12 @@ END:VCALENDAR
event = event_from_ical(ical.walk('VEVENT')[0].to_ical())
self.assertEqual(event.get_attendee_by_email("max@imum.com").get_cutype(), kolabformat.CutypeResource)
self.assertEqual(event.get_sequence(), 2)
+ self.assertTrue(event.is_recurring())
+ self.assertIsInstance(event.get_duration(), datetime.timedelta)
+ self.assertIsInstance(event.get_end(), datetime.datetime)
+ self.assertEqual(str(event.get_end()), "2014-05-23 12:30:00+01:00")
+ self.assertEqual(len(event.get_exception_dates()), 2)
+ self.assertIsInstance(event.get_exception_dates()[0], datetime.datetime)
def test_019_as_string_itip(self):
self.event.set_summary("test")