1.1 --- a/imiptools/period.py Sun Aug 02 00:11:39 2015 +0200
1.2 +++ b/imiptools/period.py Sun Aug 02 01:04:59 2015 +0200
1.3 @@ -103,6 +103,40 @@
1.4 def get_end_point(self):
1.5 return to_utc_datetime(self.get_end(), self.get_tzid())
1.6
1.7 + # Period and event recurrence logic.
1.8 +
1.9 + def is_replaced(self, recurrenceids):
1.10 +
1.11 + """
1.12 + Return whether this period refers to one of the 'recurrenceids'.
1.13 + The 'recurrenceids' should be normalised to UTC datetimes according to
1.14 + time zone information provided by their objects or be floating dates or
1.15 + datetimes requiring conversion using contextual time zone information.
1.16 + """
1.17 +
1.18 + for recurrenceid in recurrenceids:
1.19 + if self.is_affected(period, recurrenceid):
1.20 + return recurrenceid
1.21 + return None
1.22 +
1.23 + def is_affected(self, recurrenceid):
1.24 +
1.25 + """
1.26 + Return whether this period refers to 'recurrenceid'. The 'recurrenceid'
1.27 + should be normalised to UTC datetimes according to time zone information
1.28 + provided by their objects. Otherwise, this period's contextual time zone
1.29 + information is used to convert any date or floating datetime
1.30 + representation to a point in time.
1.31 + """
1.32 +
1.33 + if not recurrenceid:
1.34 + return None
1.35 + d = get_recurrence_start(recurrenceid)
1.36 + dt = get_recurrence_start_point(recurrenceid, self.tzid)
1.37 + if self.get_start() == d or self.get_start_point() == dt:
1.38 + return recurrenceid
1.39 + return None
1.40 +
1.41 class FreeBusyPeriod(Period):
1.42
1.43 "A free/busy record abstraction."
1.44 @@ -183,39 +217,6 @@
1.45 def __repr__(self):
1.46 return "RecurringPeriod%r" % (self.as_tuple(),)
1.47
1.48 -# Period and event recurrence logic.
1.49 -
1.50 -def is_replaced(period, recurrenceids, tzid):
1.51 -
1.52 - """
1.53 - Return whether 'period' refers to one of the 'recurrenceids', interpreted
1.54 - using 'tzid' if necessary. The 'recurrenceids' should be normalised to UTC
1.55 - datetimes according to time zone information provided by their objects.
1.56 - """
1.57 -
1.58 - for s in recurrenceids:
1.59 - if is_affected(period, s, tzid):
1.60 - return s
1.61 - return None
1.62 -
1.63 -def is_affected(period, recurrenceid, tzid):
1.64 -
1.65 - """
1.66 - Return whether 'period' refers to 'recurrenceid', interpreted using 'tzid'
1.67 - if necessary. The 'recurrenceid' should be normalised to UTC datetimes
1.68 - according to time zone information provided by their objects. Otherwise,
1.69 - 'tzid' is used to convert any date or floating datetime representation to a
1.70 - point in time.
1.71 - """
1.72 -
1.73 - if not recurrenceid:
1.74 - return None
1.75 - d = get_recurrence_start(recurrenceid)
1.76 - dt = get_recurrence_start_point(recurrenceid, tzid)
1.77 - if period.get_start() == d or period.get_start_point() == dt:
1.78 - return recurrenceid
1.79 - return None
1.80 -
1.81 # Time and period management.
1.82
1.83 def can_schedule(freebusy, periods, uid, recurrenceid):
1.84 @@ -340,7 +341,7 @@
1.85 # Find the range of periods potentially overlapping the period in the
1.86 # free/busy collection.
1.87
1.88 - last = bisect_right(freebusy, Period(period.get_end(), period.get_end(), period.get_tzid()))
1.89 + last = bisect_right(freebusy, Period(period.get_end(), period.get_end(), period.tzid))
1.90 startpoints = freebusy[:last]
1.91
1.92 # Find the range of periods potentially overlapping the period in a version
1.93 @@ -663,6 +664,6 @@
1.94 remove_period(freebusy, uid, recurrenceid)
1.95
1.96 for p in periods:
1.97 - insert_period(freebusy, FreeBusyPeriod(p.get_start(), p.get_end(), uid, transp, recurrenceid, summary, organiser, p.get_tzid()))
1.98 + insert_period(freebusy, FreeBusyPeriod(p.get_start(), p.get_end(), uid, transp, recurrenceid, summary, organiser, p.tzid))
1.99
1.100 # vim: tabstop=4 expandtab shiftwidth=4