1.1 --- a/imiptools/data.py Mon Mar 23 00:39:26 2015 +0100
1.2 +++ b/imiptools/data.py Tue Mar 24 16:14:55 2015 +0100
1.3 @@ -433,7 +433,7 @@
1.4 # Return a sorted list of the periods.
1.5
1.6 periods = list(periods)
1.7 - periods.sort()
1.8 + periods.sort(cmp=compare_periods(tzid))
1.9
1.10 # Exclude exception dates.
1.11
1.12 @@ -451,6 +451,17 @@
1.13
1.14 return periods
1.15
1.16 +class compare_periods:
1.17 + def __init__(self, tzid):
1.18 + self.tzid = tzid
1.19 + def __call__(self, first, second):
1.20 + first_start, first_end = first[:2]
1.21 + second_start, second_end = second[:2]
1.22 + return cmp(
1.23 + (to_datetime(first_start, self.tzid), to_datetime(first_end, self.tzid)),
1.24 + (to_datetime(second_start, self.tzid), to_datetime(second_end, self.tzid))
1.25 + )
1.26 +
1.27 def get_periods_for_freebusy(obj, periods, tzid):
1.28
1.29 """