# HG changeset patch # User Paul Boddie # Date 1438470299 -7200 # Node ID 4fa33cbc0e1f77f0a4865c1174e597ad2d574884 # Parent c8ad50a04516f27866badecc3d07d76d574ce2a0 Moved period-recurrence comparison functions to the period abstraction. Changed period initialisation to use contextual, not calculated, time zone details. diff -r c8ad50a04516 -r 4fa33cbc0e1f imiptools/period.py --- a/imiptools/period.py Sun Aug 02 00:11:39 2015 +0200 +++ b/imiptools/period.py Sun Aug 02 01:04:59 2015 +0200 @@ -103,6 +103,40 @@ def get_end_point(self): return to_utc_datetime(self.get_end(), self.get_tzid()) + # Period and event recurrence logic. + + def is_replaced(self, recurrenceids): + + """ + Return whether this period refers to one of the 'recurrenceids'. + The 'recurrenceids' should be normalised to UTC datetimes according to + time zone information provided by their objects or be floating dates or + datetimes requiring conversion using contextual time zone information. + """ + + for recurrenceid in recurrenceids: + if self.is_affected(period, recurrenceid): + return recurrenceid + return None + + def is_affected(self, recurrenceid): + + """ + Return whether this period refers to 'recurrenceid'. The 'recurrenceid' + should be normalised to UTC datetimes according to time zone information + provided by their objects. Otherwise, this period's contextual time zone + information is used to convert any date or floating datetime + representation to a point in time. + """ + + if not recurrenceid: + return None + d = get_recurrence_start(recurrenceid) + dt = get_recurrence_start_point(recurrenceid, self.tzid) + if self.get_start() == d or self.get_start_point() == dt: + return recurrenceid + return None + class FreeBusyPeriod(Period): "A free/busy record abstraction." @@ -183,39 +217,6 @@ def __repr__(self): return "RecurringPeriod%r" % (self.as_tuple(),) -# Period and event recurrence logic. - -def is_replaced(period, recurrenceids, tzid): - - """ - Return whether 'period' refers to one of the 'recurrenceids', interpreted - using 'tzid' if necessary. The 'recurrenceids' should be normalised to UTC - datetimes according to time zone information provided by their objects. - """ - - for s in recurrenceids: - if is_affected(period, s, tzid): - return s - return None - -def is_affected(period, recurrenceid, tzid): - - """ - Return whether 'period' refers to 'recurrenceid', interpreted using 'tzid' - if necessary. The 'recurrenceid' should be normalised to UTC datetimes - according to time zone information provided by their objects. Otherwise, - 'tzid' is used to convert any date or floating datetime representation to a - point in time. - """ - - if not recurrenceid: - return None - d = get_recurrence_start(recurrenceid) - dt = get_recurrence_start_point(recurrenceid, tzid) - if period.get_start() == d or period.get_start_point() == dt: - return recurrenceid - return None - # Time and period management. def can_schedule(freebusy, periods, uid, recurrenceid): @@ -340,7 +341,7 @@ # Find the range of periods potentially overlapping the period in the # free/busy collection. - last = bisect_right(freebusy, Period(period.get_end(), period.get_end(), period.get_tzid())) + last = bisect_right(freebusy, Period(period.get_end(), period.get_end(), period.tzid)) startpoints = freebusy[:last] # Find the range of periods potentially overlapping the period in a version @@ -663,6 +664,6 @@ remove_period(freebusy, uid, recurrenceid) for p in periods: - insert_period(freebusy, FreeBusyPeriod(p.get_start(), p.get_end(), uid, transp, recurrenceid, summary, organiser, p.get_tzid())) + insert_period(freebusy, FreeBusyPeriod(p.get_start(), p.get_end(), uid, transp, recurrenceid, summary, organiser, p.tzid)) # vim: tabstop=4 expandtab shiftwidth=4 diff -r c8ad50a04516 -r 4fa33cbc0e1f imipweb/event.py --- a/imipweb/event.py Sun Aug 02 00:11:39 2015 +0200 +++ b/imipweb/event.py Sun Aug 02 01:04:59 2015 +0200 @@ -493,7 +493,7 @@ recurrenceid = obj.get_recurrenceid() recurrenceids = self._get_recurrences(uid) - replaced = not recurrenceid and self.is_replaced(p, recurrenceids) + replaced = not recurrenceid and p.is_replaced(recurrenceids) # Provide a summary of the object. @@ -743,7 +743,7 @@ args = self.env.get_args() p = event_period_from_period(period) - replaced = not recurrenceid and self.is_replaced(p, recurrenceids) + replaced = not recurrenceid and p.is_replaced(recurrenceids) # Isolate the controls from neighbouring tables. @@ -830,7 +830,7 @@ partstat = participant_attr and participant_attr.get("PARTSTAT") for p in have_conflict(freebusy, periods, True): - if not recurrenceid and self.is_replaced(p, recurrenceids): + if not recurrenceid and p.is_replaced(recurrenceids): continue if ( # Unidentified or different event @@ -1000,7 +1000,7 @@ _name = self.element_name p = event_period_from_period(period) - replaced = not recurrenceid and self.is_replaced(p, recurrenceids) + replaced = not recurrenceid and p.is_replaced(recurrenceids) # Show controls for editing as organiser. @@ -1055,11 +1055,11 @@ page = self.page p = event_period_from_period(period) - replaced = not recurrenceid and self.is_replaced(p, recurrenceids) + replaced = not recurrenceid and p.is_replaced(recurrenceids) css = " ".join([ replaced and "replaced" or "", - self.is_affected(p, recurrenceid) and "affected" or "" + p.is_affected(recurrenceid) and "affected" or "" ]) formdate = show_start and p.get_form_start() or p.get_form_end() diff -r c8ad50a04516 -r 4fa33cbc0e1f imipweb/resource.py --- a/imipweb/resource.py Sun Aug 02 00:11:39 2015 +0200 +++ b/imipweb/resource.py Sun Aug 02 01:04:59 2015 +0200 @@ -23,8 +23,7 @@ from imiptools.client import Client from imiptools.data import get_uri, uri_values from imiptools.dates import get_recurrence_start_point -from imiptools.period import FreeBusyPeriod, is_affected, is_replaced, \ - remove_period, remove_affected_period +from imiptools.period import FreeBusyPeriod, remove_period, remove_affected_period from imipweb.env import CGIEnvironment import babel.dates import imip_store @@ -154,18 +153,10 @@ recurrenceid, obj.get_value("SUMMARY"), obj.get_value("ORGANIZER"), - p.get_tzid() + p.tzid )) return summary - # Period and recurrence testing. - - def is_replaced(self, period, recurrenceids): - return is_replaced(period, recurrenceids, self.get_tzid()) - - def is_affected(self, period, recurrenceid): - return is_affected(period, recurrenceid, self.get_tzid()) - # Preference methods. def get_user_locale(self):