summaryrefslogtreecommitdiffstats
path: root/pykolab
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2014-03-04 08:39:51 -0500
committerThomas Bruederli <bruederli@kolabsys.com>2014-03-04 08:39:51 -0500
commit26adad180f8ada3a21038ddbc6fc1bfa43284ca3 (patch)
tree09ef34c702b83595e99d8fc5eccdc0af6167ae32 /pykolab
parente1b881c2ce79a1dfa102cb2c5f8167f7805c08be (diff)
downloadpykolab-26adad180f8ada3a21038ddbc6fc1bfa43284ca3.tar.gz
Use libkolab bindings to compute recurring event instances + add tests for this
Diffstat (limited to 'pykolab')
-rw-r--r--pykolab/xml/event.py41
-rw-r--r--pykolab/xml/utils.py3
2 files changed, 44 insertions, 0 deletions
diff --git a/pykolab/xml/event.py b/pykolab/xml/event.py
index 70dfea2..a4e10f0 100644
--- a/pykolab/xml/event.py
+++ b/pykolab/xml/event.py
@@ -762,6 +762,47 @@ class Event(object):
return msg
+ def to_event_cal(self):
+ from kolab.calendaring import EventCal
+ return EventCal(self.event)
+
+ 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))
+ return xmlutils.from_cdatetime(next_cdatetime, True) if next_cdatetime is not None else None
+
+ def get_occurence_end_date(self, datetime):
+ if not hasattr(self, 'eventcal'):
+ return None
+
+ end_cdatetime = self.eventcal.getOccurenceEndDate(xmlutils.to_cdatetime(datetime, True))
+ return xmlutils.from_cdatetime(end_cdatetime, True) if end_cdatetime is not None else None
+
+ def get_last_occurrence(self):
+ if not hasattr(self, 'eventcal'):
+ self.eventcal = self.to_event_cal()
+
+ last = self.eventcal.getLastOccurrence()
+ return xmlutils.from_cdatetime(last, True) if last is not None else None
+
+ def get_next_instance(self, datetime):
+ next_start = self.get_next_occurence(datetime)
+ if next_start:
+ instance = Event(from_string=str(self))
+ instance.set_start(next_start)
+ instance.set_recurrence(kolabformat.RecurrenceRule()) # remove recurrence rules
+ instance.event.setRecurrenceID(instance.event.start(), False)
+ next_end = self.get_occurence_end_date(next_start)
+ if next_end:
+ instance.set_end(next_end)
+
+ return instance
+
+ return None
+
+
class EventIntegrityError(Exception):
def __init__(self, message):
Exception.__init__(self, message)
diff --git a/pykolab/xml/utils.py b/pykolab/xml/utils.py
index c09da54..c4d123c 100644
--- a/pykolab/xml/utils.py
+++ b/pykolab/xml/utils.py
@@ -21,6 +21,9 @@ def from_cdatetime(_cdatetime, with_timezone=True):
"""
Convert from kolabformat.cDateTime to datetime.date(time)
"""
+ if not _cdatetime.isValid():
+ return None
+
(
year,
month,