1.1 --- a/imiptools/data.py Tue Mar 24 17:56:12 2015 +0100
1.2 +++ b/imiptools/data.py Tue Mar 24 18:18:53 2015 +0100
1.3 @@ -426,18 +426,14 @@
1.4 origin_value = origin and ("RDATE",) or ()
1.5 for rdate in rdates:
1.6 if isinstance(rdate, tuple):
1.7 - start, end = rdate
1.8 - start = to_datetime(start, tzid)
1.9 - end = to_datetime(end, tzid)
1.10 - periods.add((start, end) + origin_value)
1.11 + periods.add(rdate + origin_value)
1.12 else:
1.13 - rdate = to_datetime(rdate, tzid)
1.14 periods.add((rdate, rdate + duration) + origin_value)
1.15
1.16 # Return a sorted list of the periods.
1.17
1.18 periods = list(periods)
1.19 - periods.sort()
1.20 + periods.sort(cmp=compare_periods(tzid))
1.21
1.22 # Exclude exception dates.
1.23
1.24 @@ -446,12 +442,8 @@
1.25 if exdates:
1.26 for exdate in exdates:
1.27 if isinstance(exdate, tuple):
1.28 - start, end = exdate
1.29 - start = to_datetime(start, tzid)
1.30 - end = to_datetime(end, tzid)
1.31 - period = start, end
1.32 + period = exdate
1.33 else:
1.34 - exdate = to_datetime(exdate, tzid)
1.35 period = (exdate, exdate + duration)
1.36 i = bisect_left(periods, period)
1.37 while i < len(periods) and periods[i][:2] == period:
1.38 @@ -459,6 +451,17 @@
1.39
1.40 return periods
1.41
1.42 +class compare_periods:
1.43 + def __init__(self, tzid):
1.44 + self.tzid = tzid
1.45 + def __call__(self, first, second):
1.46 + first_start, first_end = first[:2]
1.47 + second_start, second_end = second[:2]
1.48 + return cmp(
1.49 + (to_datetime(first_start, self.tzid), to_datetime(first_end, self.tzid)),
1.50 + (to_datetime(second_start, self.tzid), to_datetime(second_end, self.tzid))
1.51 + )
1.52 +
1.53 def get_periods_for_freebusy(obj, periods, tzid):
1.54
1.55 """