1.1 --- a/imiptools/data.py Sun Feb 08 01:26:33 2015 +0100
1.2 +++ b/imiptools/data.py Sun Feb 08 18:39:03 2015 +0100
1.3 @@ -21,7 +21,8 @@
1.4
1.5 from datetime import datetime, timedelta
1.6 from email.mime.text import MIMEText
1.7 -from imiptools.dates import format_datetime, get_datetime, to_utc_datetime
1.8 +from imiptools.dates import format_datetime, get_datetime, get_freebusy_period, \
1.9 + to_utc_datetime
1.10 from vCalendar import iterwrite, parse, ParseError, to_dict, to_node
1.11 from vRecurrence import get_parameters, get_rule
1.12 import email.utils
1.13 @@ -81,6 +82,10 @@
1.14 def get_periods(self, window_size=100):
1.15 return get_periods(self, window_size)
1.16
1.17 + def get_periods_for_freebusy(self, tzid, window_size=100):
1.18 + periods = self.get_periods(window_size)
1.19 + return get_periods_for_freebusy(self, periods, tzid)
1.20 +
1.21 # Construction and serialisation.
1.22
1.23 def make_calendar(nodes, method=None):
1.24 @@ -307,10 +312,25 @@
1.25 for start in selector.materialise(dtstart, window_end, parameters.get("COUNT"), parameters.get("BYSETPOS")):
1.26 start = datetime(*start, tzinfo=timezone("UTC"))
1.27 end = start + duration
1.28 - periods.append((format_datetime(start), format_datetime(end)))
1.29 + periods.append((start, end))
1.30 else:
1.31 - periods = [(format_datetime(dtstart), format_datetime(dtend))]
1.32 + periods = [(dtstart, dtend)]
1.33
1.34 return periods
1.35
1.36 +def get_periods_for_freebusy(obj, periods, tzid):
1.37 +
1.38 + start, start_attr = obj.get_datetime_item("DTSTART")
1.39 + end, end_attr = obj.get_datetime_item("DTEND")
1.40 +
1.41 + tzid = start_attr.get("TZID") or end_attr.get("TZID") or tzid
1.42 +
1.43 + l = []
1.44 +
1.45 + for start, end in periods:
1.46 + start, end = get_freebusy_period(start, end, tzid)
1.47 + l.append((format_datetime(start), format_datetime(end)))
1.48 +
1.49 + return l
1.50 +
1.51 # vim: tabstop=4 expandtab shiftwidth=4