# HG changeset patch # User Paul Boddie # Date 1431901733 -7200 # Node ID 6078f2a58c3c7268d9d5eda2002a12f62ad8a218 # Parent ade19f50b58e7a4b779bbb69f1803aaa1896baa1 Distinguish between the stated start of a period and the start point of a period, using the former to define recurrence identifiers and the latter to locate recurrence periods in free/busy collections. diff -r ade19f50b58e -r 6078f2a58c3c imiptools/dates.py --- a/imiptools/dates.py Mon May 18 00:26:37 2015 +0200 +++ b/imiptools/dates.py Mon May 18 00:28:53 2015 +0200 @@ -431,7 +431,16 @@ return dtstart_attr and dtstart_attr.get("TZID") or dtend_attr and dtend_attr.get("TZID") or None -def get_recurrence_start(recurrenceid, tzid): +def get_recurrence_start(recurrenceid): + + """ + Return 'recurrenceid' in a form suitable for comparison with period start + dates or datetimes. + """ + + return get_datetime(recurrenceid) + +def get_recurrence_start_point(recurrenceid, tzid): """ Return 'recurrenceid' in a form suitable for comparison with free/busy start @@ -440,13 +449,22 @@ return to_utc_datetime(get_datetime(recurrenceid), tzid) -def to_recurrence_start(recurrenceid, tzid): +def to_recurrence_start(recurrenceid): + + """ + Return 'recurrenceid' in a form suitable for use as an unambiguous + identifier. + """ + + return format_datetime(get_recurrence_start(recurrenceid)) + +def to_recurrence_start_point(recurrenceid, tzid): """ Return 'recurrenceid' in a form suitable for use as an unambiguous identifier, using 'tzid' to convert recurrence identifiers that are dates. """ - return format_datetime(get_recurrence_start(recurrenceid, tzid)) + return format_datetime(get_recurrence_start_point(recurrenceid, tzid)) # vim: tabstop=4 expandtab shiftwidth=4 diff -r ade19f50b58e -r 6078f2a58c3c imiptools/handlers/__init__.py --- a/imiptools/handlers/__init__.py Mon May 18 00:26:37 2015 +0200 +++ b/imiptools/handlers/__init__.py Mon May 18 00:28:53 2015 +0200 @@ -26,7 +26,8 @@ from imiptools.data import Object, \ get_address, get_uri, get_value, \ is_new_object, uri_dict, uri_item, uri_values -from imiptools.dates import format_datetime, to_recurrence_start, to_timezone +from imiptools.dates import format_datetime, to_recurrence_start_point, \ + to_timezone from imiptools.period import can_schedule, remove_period, \ remove_additional_periods, remove_affected_period, \ update_freebusy @@ -120,18 +121,20 @@ # Convenience methods for modifying free/busy collections. - def to_recurrence_start(self, recurrenceid): + def to_recurrence_start_point(self, recurrenceid): "Get 'recurrenceid' in a form suitable for matching free/busy entries." - return to_recurrence_start(recurrenceid, self.get_tzid()) + tzid = self.obj.get_tzid() or self.get_tzid() + return to_recurrence_start_point(recurrenceid, tzid) def remove_from_freebusy(self, freebusy): "Remove this event from the given 'freebusy' collection." if not remove_period(freebusy, self.uid, self.recurrenceid) and self.recurrenceid: - remove_affected_period(freebusy, self.uid, self.recurrenceid) + tzid = self.obj.get_tzid() or self.get_tzid() + remove_affected_period(freebusy, self.uid, self.to_recurrence_start_point(self.recurrenceid)) def remove_freebusy_for_recurrences(self, freebusy, recurrenceids=None): @@ -144,7 +147,7 @@ """ if self.recurrenceid: - recurrenceid = self.to_recurrence_start(self.recurrenceid) + recurrenceid = self.to_recurrence_start_point(self.recurrenceid) remove_affected_period(freebusy, self.uid, recurrenceid) else: # Remove obsolete recurrence periods. @@ -155,7 +158,7 @@ if recurrenceids: for recurrenceid in recurrenceids: - recurrenceid = self.to_recurrence_start(recurrenceid) + recurrenceid = self.to_recurrence_start_point(recurrenceid) remove_affected_period(freebusy, self.uid, recurrenceid) def _update_freebusy(self, freebusy, periods, recurrenceid, transp=None): diff -r ade19f50b58e -r 6078f2a58c3c imipweb/handler.py --- a/imipweb/handler.py Mon May 18 00:26:37 2015 +0200 +++ b/imipweb/handler.py Mon May 18 00:28:53 2015 +0200 @@ -159,7 +159,7 @@ for p in to_unschedule: if not p.origin: continue - obj["RECURRENCE-ID"] = [(format_datetime(p.get_start_point()), {})] + obj["RECURRENCE-ID"] = [(format_datetime(p.get_start()), {})] parts.append(obj.to_part("CANCEL")) # Send the updated event, along with a cancellation for each of the diff -r ade19f50b58e -r 6078f2a58c3c imipweb/resource.py --- a/imipweb/resource.py Mon May 18 00:26:37 2015 +0200 +++ b/imipweb/resource.py Mon May 18 00:28:53 2015 +0200 @@ -23,7 +23,7 @@ from imiptools.client import Client from imiptools.data import get_uri, get_window_end, Object, uri_values from imiptools.dates import format_datetime, format_time, get_recurrence_start, \ - to_recurrence_start + get_recurrence_start_point, to_recurrence_start_point from imiptools.period import FreeBusyPeriod, \ remove_period, remove_affected_period, update_freebusy from imipweb.env import CGIEnvironment @@ -149,7 +149,7 @@ recurrenceid, obj.get_value("SUMMARY"), obj.get_value("ORGANIZER"), - self.get_tzid() + p.get_tzid() )) return summary @@ -157,16 +157,18 @@ def is_replaced(self, period, recurrenceids): for s in recurrenceids: - dt = get_recurrence_start(s, self.get_tzid()) - if period.get_start() == dt: + d = get_recurrence_start(s) + dt = get_recurrence_start_point(s, self.get_tzid()) + if period.get_start() == d or period.get_start_point() == dt: return s return None def is_affected(self, period, recurrenceid): if not recurrenceid: return None - dt = get_recurrence_start(recurrenceid, self.get_tzid()) - if period.get_start() == dt: + d = get_recurrence_start(recurrenceid) + dt = get_recurrence_start_point(recurrenceid, self.get_tzid()) + if period.get_start() == d or period.get_start_point() == dt: return recurrenceid return None @@ -221,9 +223,10 @@ # Subtract any recurrences from the free/busy details of a parent # object. + # NOTE: The time zone may need obtaining using the object details. for recurrenceid in self._get_recurrences(uid): - remove_affected_period(freebusy, uid, to_recurrence_start(recurrenceid)) + remove_affected_period(freebusy, uid, to_recurrence_start_point(recurrenceid, self.get_tzid())) self.store.set_freebusy(self.user, freebusy) self.publish_freebusy(freebusy)