summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pykolab/xml/event.py10
-rw-r--r--pykolab/xml/utils.py2
-rw-r--r--tests/unit/test-003-event.py12
3 files changed, 20 insertions, 4 deletions
diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py
index 0e7c333..72c5e07 100644
--- a/pykolab/xml/event.py
+++ b/pykolab/xml/event.py
@@ -1134,17 +1134,21 @@ class Event(object):
from kolab.calendaring import EventCal
return EventCal(self.event)
- def get_next_occurence(self, datetime):
+ def get_next_occurence(self, _datetime):
if not hasattr(self, 'eventcal'):
self.eventcal = self.to_event_cal()
- next_cdatetime = self.eventcal.getNextOccurence(xmlutils.to_cdatetime(datetime, True))
+ next_cdatetime = self.eventcal.getNextOccurence(xmlutils.to_cdatetime(_datetime, True))
next_datetime = xmlutils.from_cdatetime(next_cdatetime, True) if next_cdatetime is not None else None
# cut infinite recurrence at a reasonable point
- if next_datetime and not self.get_last_occurrence() and next_datetime > self._recurrence_end():
+ if next_datetime and not self.get_last_occurrence() and next_datetime > xmlutils.to_dt(self._recurrence_end()):
next_datetime = None
+ # next_datetime is always a cdatetime, convert to date if necessary
+ if not isinstance(self.get_start(), datetime.datetime):
+ next_datetime = datetime.date(next_datetime.year, next_datetime.month, next_datetime.day)
+
return next_datetime
def get_occurence_end_date(self, datetime):
diff --git a/pykolab/xml/utils.py b/pykolab/xml/utils.py
index 97b72af..a3ecbcf 100644
--- a/pykolab/xml/utils.py
+++ b/pykolab/xml/utils.py
@@ -14,7 +14,7 @@ def to_dt(dt):
"""
if isinstance(dt, datetime.date) and not isinstance(dt, datetime.datetime) or dt is not None and not hasattr(dt, 'hour'):
- dt = datetime.datetime(dt.year, dt.month, dt.day, 0, 0, 0, 0, tzinfo=tzlocal())
+ dt = datetime.datetime(dt.year, dt.month, dt.day, 0, 0, 0, 0, tzinfo=pytz.utc)
elif isinstance(dt, datetime.datetime):
if dt.tzinfo == None:
diff --git a/tests/unit/test-003-event.py b/tests/unit/test-003-event.py
index 7fae6eb..02bc8df 100644
--- a/tests/unit/test-003-event.py
+++ b/tests/unit/test-003-event.py
@@ -533,6 +533,18 @@ END:VEVENT
self.assertEqual(next_instance.get_start().month, 7)
self.assertFalse(next_instance.is_recurring())
+ # check get_next_occurence() with an infinitely recurring all-day event
+ rrule = kolabformat.RecurrenceRule()
+ rrule.setFrequency(kolabformat.RecurrenceRule.Yearly)
+ self.event.set_recurrence(rrule);
+
+ self.event.set_start(datetime.date(2014, 5, 1))
+ self.event.set_end(datetime.date(2014, 5, 1))
+ next_date = self.event.get_next_occurence(datetime.date(2015, 1, 1))
+ self.assertIsInstance(next_date, datetime.date)
+ self.assertEqual(next_date.year, 2015)
+ self.assertEqual(next_date.month, 5)
+
def test_021_calendaring_no_recurrence(self):
_start = datetime.datetime(2014, 2, 1, 14, 30, 00, tzinfo=pytz.timezone("Europe/London"))
self.event = Event()