1.1 --- a/imiptools/data.py Wed Feb 11 17:06:21 2015 +0100
1.2 +++ b/imiptools/data.py Wed Feb 11 17:07:32 2015 +0100
1.3 @@ -23,6 +23,7 @@
1.4 from email.mime.text import MIMEText
1.5 from imiptools.dates import format_datetime, get_datetime, get_freebusy_period, \
1.6 to_timezone, to_utc_datetime
1.7 +from imiptools.period import period_overlaps
1.8 from pytz import timezone
1.9 from vCalendar import iterwrite, parse, ParseError, to_dict, to_node
1.10 from vRecurrence import get_parameters, get_rule
1.11 @@ -106,13 +107,17 @@
1.12 nodes
1.13 )
1.14
1.15 -def make_freebusy(freebusy, uid, organiser, organiser_attr=None, attendee=None, attendee_attr=None):
1.16 +def make_freebusy(freebusy, uid, organiser, organiser_attr=None, attendee=None,
1.17 + attendee_attr=None, dtstart=None, dtend=None):
1.18
1.19 """
1.20 Return a calendar node defining the free/busy details described in the given
1.21 'freebusy' list, employing the given 'uid', for the given 'organiser' and
1.22 optional 'organiser_attr', with the optional 'attendee' providing recipient
1.23 details together with the optional 'attendee_attr'.
1.24 +
1.25 + The result will be constrained to the 'dtstart' and 'dtend' period if these
1.26 + parameters are given.
1.27 """
1.28
1.29 record = []
1.30 @@ -126,7 +131,17 @@
1.31 rwrite(("UID", {}, uid))
1.32
1.33 if freebusy:
1.34 - for start, end, uid, transp in freebusy:
1.35 +
1.36 + # Get a constrained view if start and end limits are specified.
1.37 +
1.38 + periods = dtstart and dtend and period_overlaps(freebusy, (dtstart, dtend), True) or freebusy
1.39 +
1.40 + # Write the limits of the resource.
1.41 +
1.42 + rwrite(("DTSTART", {"VALUE" : "DATE-TIME"}, periods[0][0]))
1.43 + rwrite(("DTEND", {"VALUE" : "DATE-TIME"}, periods[-1][1]))
1.44 +
1.45 + for start, end, uid, transp in periods:
1.46 if transp == "OPAQUE":
1.47 rwrite(("FREEBUSY", {"FBTYPE" : "BUSY"}, "/".join([start, end])))
1.48