1.1 --- a/imiptools/data.py Mon Apr 18 21:07:41 2016 +0200
1.2 +++ b/imiptools/data.py Tue Apr 19 00:53:59 2016 +0200
1.3 @@ -44,6 +44,25 @@
1.4 "Access to calendar structures."
1.5
1.6 def __init__(self, fragment):
1.7 +
1.8 + """
1.9 + Initialise the object with the given 'fragment'. This must be a
1.10 + dictionary mapping an object type (such as "VEVENT") to a tuple
1.11 + containing the object details and attributes, each being a dictionary
1.12 + itself.
1.13 +
1.14 + The result of parse_object can be processed to obtain a fragment by
1.15 + obtaining a collection of records for an object type. For example:
1.16 +
1.17 + l = parse_object(f, encoding, "VCALENDAR")
1.18 + events = l["VEVENT"]
1.19 + event = events[0]
1.20 +
1.21 + Then, the specific object must be presented as follows:
1.22 +
1.23 + object = Object({"VEVENT" : event})
1.24 + """
1.25 +
1.26 self.objtype, (self.details, self.attr) = fragment.items()[0]
1.27
1.28 def get_uid(self):
1.29 @@ -219,7 +238,7 @@
1.30
1.31 return (dtstart, dtstart_attr), (dtend, dtend_attr)
1.32
1.33 - def get_periods(self, tzid, end=None):
1.34 + def get_periods(self, tzid, end=None, inclusive=False):
1.35
1.36 """
1.37 Return periods defined by this object, employing the given 'tzid' where
1.38 @@ -228,9 +247,34 @@
1.39
1.40 If 'end' is omitted, only explicit recurrences and recurrences from
1.41 explicitly-terminated rules will be returned.
1.42 +
1.43 + If 'inclusive' is set to a true value, any period occurring at the 'end'
1.44 + will be included.
1.45 + """
1.46 +
1.47 + return get_periods(self, tzid, end, inclusive)
1.48 +
1.49 + def has_period(self, tzid, period):
1.50 +
1.51 + """
1.52 + Return whether this object, employing the given 'tzid' where no time
1.53 + zone information is defined, has the given 'period'.
1.54 """
1.55
1.56 - return get_periods(self, tzid, end)
1.57 + return period in self.get_periods(tzid, period.get_start_point(), inclusive=True)
1.58 +
1.59 + def has_recurrence(self, tzid, recurrenceid):
1.60 +
1.61 + """
1.62 + Return whether this object, employing the given 'tzid' where no time
1.63 + zone information is defined, has the given 'recurrenceid'.
1.64 + """
1.65 +
1.66 + start_point = self.get_recurrence_start_point(recurrenceid, tzid)
1.67 + for p in self.get_periods(tzid, start_point, inclusive=True):
1.68 + if p.get_start_point() == start_point:
1.69 + return True
1.70 + return False
1.71
1.72 def get_active_periods(self, recurrenceids, tzid, end=None):
1.73