summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2015-03-02 15:36:13 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2015-03-02 15:36:13 (GMT)
commit14c14b74411d6a32d5948cdbdc09eaf1ce8b7c5a (patch)
tree68044823b984fe2bb6062efc456dcdc54f0931d1
parent3cc3391170e54fb3e4bf477562bc2ef4bf8885c3 (diff)
downloadpykolab-14c14b74411d6a32d5948cdbdc09eaf1ce8b7c5a.tar.gz
Make sure stored recurrence-id properties are returned as the correct date/datetime type (#4752)
-rw-r--r--pykolab/xml/event.py10
-rw-r--r--tests/unit/test-003-event.py8
2 files changed, 17 insertions, 1 deletions
diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py
index 7a81ab8..ab643a5 100644
--- a/pykolab/xml/event.py
+++ b/pykolab/xml/event.py
@@ -700,7 +700,15 @@ class Event(object):
def get_recurrence_id(self):
self.thisandfuture = self.event.thisAndFuture();
- return xmlutils.from_cdatetime(self.event.recurrenceID(), True)
+ recurrence_id = xmlutils.from_cdatetime(self.event.recurrenceID(), True)
+
+ # fix recurrence-id type if stored as date instead of datetime
+ if recurrence_id is not None and isinstance(recurrence_id, datetime.date):
+ dtstart = self.get_start()
+ if not type(recurrence_id) == type(dtstart):
+ recurrence_id = datetime.datetime.combine(recurrence_id, dtstart.time()).replace(tzinfo=dtstart.tzinfo)
+
+ return recurrence_id
def get_thisandfuture(self):
self.thisandfuture = self.event.thisAndFuture();
diff --git a/tests/unit/test-003-event.py b/tests/unit/test-003-event.py
index 5798101..f039ca1 100644
--- a/tests/unit/test-003-event.py
+++ b/tests/unit/test-003-event.py
@@ -814,6 +814,14 @@ END:VEVENT
self.assertIsInstance(occurrence, Event)
self.assertEqual(str(occurrence.get_recurrence_id()), "2014-08-15 10:00:00+01:00")
+ # set invalid date-only recurrence-id
+ exception.set_recurrence_id(datetime.date(2014,8,16))
+ event.add_exception(exception)
+
+ inst = event.get_next_instance(_recurrence_id);
+ self.assertIsInstance(inst, Event)
+ self.assertIsInstance(inst.get_recurrence_id(), datetime.datetime)
+
def test_023_load_from_message(self):
event = event_from_message(event_from_ical(ical_event).to_message())
event.set_sequence(3)