summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2015-02-24 01:48:15 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2015-02-24 01:48:15 (GMT)
commitb797505f35b3fbaa0eaf202ed4d11d5f4aa39f75 (patch)
treea73c3d5aea02a72e11ee00a4fdcbd8a0be1ab0b8
parentc031071888487b5ab2d3d4501e8583e15f7ed6ce (diff)
downloadpykolab-b797505f35b3fbaa0eaf202ed4d11d5f4aa39f75.tar.gz
Fix event.get_instance() calls for all-day events (#4709)
-rw-r--r--pykolab/xml/event.py5
-rw-r--r--tests/unit/test-003-event.py27
2 files changed, 30 insertions, 2 deletions
diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py
index 31ea476..4158d31 100644
--- a/pykolab/xml/event.py
+++ b/pykolab/xml/event.py
@@ -1379,9 +1379,10 @@ class Event(object):
def get_instance(self, _datetime):
# If no timezone information is given, use the one from event start
- if _datetime.tzinfo == None:
+ if isinstance(_datetime, datetime.datetime) and _datetime.tzinfo == None:
_start = self.get_start()
- _datetime = _datetime.replace(tzinfo=_start.tzinfo)
+ if hasattr(_start, 'tzinfo'):
+ _datetime = _datetime.replace(tzinfo=_start.tzinfo)
instance = self.get_next_instance(_datetime - datetime.timedelta(days=1))
while instance:
diff --git a/tests/unit/test-003-event.py b/tests/unit/test-003-event.py
index cc27e58..1f9f36b 100644
--- a/tests/unit/test-003-event.py
+++ b/tests/unit/test-003-event.py
@@ -690,6 +690,33 @@ END:VEVENT
occurrence = event.get_next_instance(event.get_start())
self.assertEqual(occurrence.get_summary(), "Exception")
+ def test_021_allday_recurrence(self):
+ rrule = kolabformat.RecurrenceRule()
+ rrule.setFrequency(kolabformat.RecurrenceRule.Daily)
+ rrule.setCount(10)
+
+ self.event = Event()
+ self.event.set_summary('alldays')
+ self.event.set_recurrence(rrule);
+
+ _start = datetime.date(2015,1,1)
+ self.event.set_start(_start)
+ self.event.set_end(_start)
+
+ exdate = datetime.date(2015,1,5)
+ xmlexception = Event(from_string=str(self.event))
+ xmlexception.set_start(exdate)
+ xmlexception.set_end(exdate)
+ xmlexception.set_recurrence_id(exdate, False)
+ xmlexception.set_status('CANCELLED')
+ self.event.add_exception(xmlexception)
+
+ inst3 = self.event.get_instance(datetime.date(2015,1,3))
+ self.assertEqual(inst3.get_start(), datetime.date(2015,1,3))
+
+ inst5 = self.event.get_instance(exdate)
+ self.assertEqual(inst5.get_status(True), 'CANCELLED')
+
def test_021_ical_exceptions(self):
self.event.set_summary("test")
self.event.set_start(datetime.datetime(2014, 05, 23, 11, 00, 00, tzinfo=pytz.timezone("Europe/London")))