in src/pycalendar/icalendar/vfreebusy.py [0:0]
def cacheBusyTime(self):
# Clear out any existing cache
self.mBusyTime = []
# Get all FREEBUSY items and add those that are BUSY
min_start = DateTime()
max_end = DateTime()
props = self.getProperties()
result = props.get(definitions.cICalProperty_FREEBUSY, ())
for iter in result:
# Check the properties FBTYPE parameter
type = 0
is_busy = False
if iter.hasParameter(definitions.cICalParameter_FBTYPE):
fbyype = iter.getParameterValue(definitions.cICalParameter_FBTYPE)
if fbyype.upper() == definitions.cICalParameter_FBTYPE_BUSY:
is_busy = True
type = FreeBusy.BUSY
elif fbyype.upper() == definitions.cICalParameter_FBTYPE_BUSYUNAVAILABLE:
is_busy = True
type = FreeBusy.BUSYUNAVAILABLE
elif fbyype.upper() == definitions.cICalParameter_FBTYPE_BUSYTENTATIVE:
is_busy = True
type = FreeBusy.BUSYTENTATIVE
else:
is_busy = False
type = FreeBusy.FREE
else:
# Default is busy when no parameter
is_busy = True
type = FreeBusy.BUSY
# Add this period
if is_busy:
multi = iter.getMultiValue()
if (multi is not None) and (multi.getType() == Value.VALUETYPE_PERIOD):
for o in multi.getValues():
# Double-check type
period = None
if isinstance(o, PeriodValue):
period = o
# Double-check type
if period is not None:
self.mBusyTime.append(FreeBusy(type, period.getValue()))
if len(self.mBusyTime) == 1:
min_start = period.getValue().getStart()
max_end = period.getValue().getEnd()
else:
if min_start > period.getValue().getStart():
min_start = period.getValue().getStart()
if max_end < period.getValue().getEnd():
max_end = period.getValue().getEnd()
# If nothing present, empty the list
if len(self.mBusyTime) == 0:
self.mBusyTime = None
else:
# Sort the list by period
self.mBusyTime.sort(cmp=lambda x, y: x.getPeriod().getStart().compareDateTime(y.getPeriod().getStart()))
# Determine range
start = DateTime()
end = DateTime()
if self.mHasStart:
start = self.mStart
else:
start = min_start
if self.mHasEnd:
end = self.mEnd
else:
end = max_end
self.mSpanPeriod = Period(start, end)
self.mCachedBusyTime = True