1.1 --- a/imiptools/data.py Mon May 18 00:28:53 2015 +0200
1.2 +++ b/imiptools/data.py Mon May 18 15:08:29 2015 +0200
1.3 @@ -127,6 +127,12 @@
1.4 return get_periods(self, tzid, end)
1.5
1.6 def get_tzid(self):
1.7 +
1.8 + """
1.9 + Return a time zone identifier used by the start or end datetimes,
1.10 + potentially suitable for converting dates to datetimes.
1.11 + """
1.12 +
1.13 if not self.has_key("DTSTART"):
1.14 return None
1.15 dtstart, dtstart_attr = self.get_datetime_item("DTSTART")
1.16 @@ -149,7 +155,7 @@
1.17 )
1.18
1.19 def make_freebusy(freebusy, uid, organiser, organiser_attr=None, attendee=None,
1.20 - attendee_attr=None, dtstart=None, dtend=None):
1.21 + attendee_attr=None, period=None):
1.22
1.23 """
1.24 Return a calendar node defining the free/busy details described in the given
1.25 @@ -157,8 +163,7 @@
1.26 optional 'organiser_attr', with the optional 'attendee' providing recipient
1.27 details together with the optional 'attendee_attr'.
1.28
1.29 - The result will be constrained to the 'dtstart' and 'dtend' period if these
1.30 - parameters are given.
1.31 + The result will be constrained to the 'period' if specified.
1.32 """
1.33
1.34 record = []
1.35 @@ -175,19 +180,17 @@
1.36
1.37 # Get a constrained view if start and end limits are specified.
1.38
1.39 - periods = dtstart and dtend and \
1.40 - period_overlaps(freebusy, Period(dtstart, dtend), True) or \
1.41 - freebusy
1.42 + periods = period and period_overlaps(freebusy, period, True) or freebusy
1.43
1.44 # Write the limits of the resource.
1.45
1.46 - rwrite(("DTSTART", {"VALUE" : "DATE-TIME"}, format_datetime(periods[0].get_start())))
1.47 - rwrite(("DTEND", {"VALUE" : "DATE-TIME"}, format_datetime(periods[-1].get_end())))
1.48 + rwrite(("DTSTART", {"VALUE" : "DATE-TIME"}, format_datetime(periods[0].get_start_point())))
1.49 + rwrite(("DTEND", {"VALUE" : "DATE-TIME"}, format_datetime(periods[-1].get_end_point())))
1.50
1.51 for p in periods:
1.52 if p.transp == "OPAQUE":
1.53 rwrite(("FREEBUSY", {"FBTYPE" : "BUSY"}, "/".join(
1.54 - map(format_datetime, [p.get_start(), p.get_end()])
1.55 + map(format_datetime, [p.get_start_point(), p.get_end_point()])
1.56 )))
1.57
1.58 return ("VFREEBUSY", {}, record)
1.59 @@ -334,6 +337,13 @@
1.60 return to_utc_datetime(dt, date_tzid)
1.61
1.62 def get_datetime_item(d, name):
1.63 +
1.64 + """
1.65 + Return the value provided by 'd' for 'name' as a datetime or as a date,
1.66 + together with the attributes describing it. Return None if no value exists
1.67 + for 'name' in 'd'.
1.68 + """
1.69 +
1.70 t = get_item(d, name)
1.71 if not t:
1.72 return None
1.73 @@ -421,7 +431,7 @@
1.74 else:
1.75 dtend, dtend_attr = dtstart, dtstart_attr
1.76
1.77 - tzid = get_tzid(dtstart_attr, dtend_attr) or tzid
1.78 + tzid = obj.get_tzid() or tzid
1.79
1.80 if not rrule:
1.81 periods = [RecurringPeriod(dtstart, dtend, tzid, "DTSTART", dtstart_attr, dtend_attr)]
1.82 @@ -468,9 +478,9 @@
1.83 if exdates:
1.84 for exdate in exdates:
1.85 if isinstance(exdate, tuple):
1.86 - period = Period(exdate[0], exdate[1])
1.87 + period = Period(exdate[0], exdate[1], tzid)
1.88 else:
1.89 - period = Period(exdate, exdate + duration)
1.90 + period = Period(exdate, exdate + duration, tzid)
1.91 i = bisect_left(periods, period)
1.92 while i < len(periods) and periods[i] == period:
1.93 del periods[i]