Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Fix boundary case on an expand report with an all-day event.

  • Loading branch information
cyrusdaboo committed Feb 15, 2013
1 parent c4a91bb commit 1bc8cc993eec21921f580faa78963f10825c553d
Showing with 49 additions and 13 deletions.
  1. +49 −13 twistedcaldav/instance.py
@@ -104,6 +104,9 @@ def __init__(self, ignoreInvalidInstances=False, normalizeFunction=normalizeForI
self.ignoreInvalidInstances = ignoreInvalidInstances
self.normalizeFunction = normalizeFunction

self.adjustedLowerLimit = None
self.adjustedUpperLimit = None


def __iter__(self):
# Return keys in sorted order via iterator
@@ -184,6 +187,28 @@ def addInstance(self, instance):
raise TooManyInstancesError()


def _setupLimits(self, dt, lowerLimit, upperLimit):
"""
Change the limits to account for testing against DATE only values. The lower limit
is simply truncated to its date value. The upper limit is truncated to one day past
the date value.
"""

if self.adjustedUpperLimit is None:
if dt.isDateOnly():
if lowerLimit:
self.adjustedLowerLimit = lowerLimit.duplicate()
self.adjustedLowerLimit.setDateOnly(True)
self.adjustedUpperLimit = upperLimit.duplicate()
self.adjustedUpperLimit.setDateOnly(True)
self.adjustedUpperLimit.offsetDay(1)
else:
self.adjustedLowerLimit = lowerLimit
self.adjustedUpperLimit = upperLimit

return (self.adjustedLowerLimit, self.adjustedUpperLimit,)


def _getMasterEventDetails(self, component):
"""
Logic here comes from RFC4791 Section 9.9
@@ -210,7 +235,7 @@ def _getMasterEventDetails(self, component):
return (rulestart, start, end, duration,)


def _addMasterEventComponent(self, component, lowerLimit, upperlimit):
def _addMasterEventComponent(self, component, lowerLimit, upperLimit):
"""
Add the specified master VEVENT Component to the instance list, expanding it
within the supplied time range.
@@ -223,10 +248,11 @@ def _addMasterEventComponent(self, component, lowerLimit, upperlimit):
return
rulestart, start, end, duration = details

self._addMasterComponent(component, lowerLimit, upperlimit, rulestart, start, end, duration)
lowerLimit, upperLimit = self._setupLimits(start, lowerLimit, upperLimit)
self._addMasterComponent(component, lowerLimit, upperLimit, rulestart, start, end, duration)


def _addOverrideEventComponent(self, component, lowerLimit, upperlimit, got_master):
def _addOverrideEventComponent(self, component, lowerLimit, upperLimit, got_master):
"""
Add the specified overridden VEVENT Component to the instance list, replacing
the one generated by the master component.
@@ -241,7 +267,8 @@ def _addOverrideEventComponent(self, component, lowerLimit, upperlimit, got_mast
return
_ignore_rulestart, start, end, _ignore_duration = details

self._addOverrideComponent(component, lowerLimit, upperlimit, start, end, got_master)
lowerLimit, upperLimit = self._setupLimits(start, lowerLimit, upperLimit)
self._addOverrideComponent(component, lowerLimit, upperLimit, start, end, got_master)


def _getMasterToDoDetails(self, component):
@@ -290,7 +317,7 @@ def _getMasterToDoDetails(self, component):
return (rulestart, start, end, duration,)


def _addMasterToDoComponent(self, component, lowerLimit, upperlimit):
def _addMasterToDoComponent(self, component, lowerLimit, upperLimit):
"""
Add the specified master VTODO Component to the instance list, expanding it
within the supplied time range.
@@ -302,10 +329,11 @@ def _addMasterToDoComponent(self, component, lowerLimit, upperlimit):
return
rulestart, start, end, duration = details

self._addMasterComponent(component, lowerLimit, upperlimit, rulestart, start, end, duration)
lowerLimit, upperLimit = self._setupLimits(start, lowerLimit, upperLimit)
self._addMasterComponent(component, lowerLimit, upperLimit, rulestart, start, end, duration)


def _addOverrideToDoComponent(self, component, lowerLimit, upperlimit, got_master):
def _addOverrideToDoComponent(self, component, lowerLimit, upperLimit, got_master):
"""
Add the specified overridden VTODO Component to the instance list, replacing
the one generated by the master component.
@@ -320,7 +348,8 @@ def _addOverrideToDoComponent(self, component, lowerLimit, upperlimit, got_maste
return
_ignore_rulestart, start, end, _ignore_duration = details

self._addOverrideComponent(component, lowerLimit, upperlimit, start, end, got_master)
lowerLimit, upperLimit = self._setupLimits(start, lowerLimit, upperLimit)
self._addOverrideComponent(component, lowerLimit, upperLimit, start, end, got_master)


def _addMasterComponent(self, component, lowerLimit, upperlimit, rulestart, start, end, duration):
@@ -422,7 +451,7 @@ def _addOverrideComponent(self, component, lowerLimit, upperlimit, start, end, g
self.addInstance(Instance(component, start, end, originalStart, False, False))


def _addFreeBusyComponent(self, component, lowerLimit, upperlimit):
def _addFreeBusyComponent(self, component, lowerLimit, upperLimit):
"""
Add the specified master VFREEBUSY Component to the instance list, expanding it
within the supplied time range.
@@ -435,8 +464,11 @@ def _addFreeBusyComponent(self, component, lowerLimit, upperlimit):
if end is None and start is not None:
raise ValueError("VFREEBUSY component must have both DTSTART and DTEND: %r" % (component,))

if start:
lowerLimit, upperLimit = self._setupLimits(start, lowerLimit, upperLimit)

# If the free busy is beyond the end of the range we want, ignore it
if start is not None and start >= upperlimit:
if start is not None and start >= upperLimit:
return

# If the free busy is before the start of the range we want, ignore it
@@ -450,14 +482,14 @@ def _addFreeBusyComponent(self, component, lowerLimit, upperlimit):
for period in fb.value():
# Ignore if period starts after limit
period = period.getValue()
if period.getStart() >= upperlimit:
if period.getStart() >= upperLimit:
continue
start = self.normalizeFunction(period.getStart())
end = self.normalizeFunction(period.getEnd())
self.addInstance(Instance(component, start, end))


def _addAvailabilityComponent(self, component, lowerLimit, upperlimit):
def _addAvailabilityComponent(self, component, lowerLimit, upperLimit):
"""
Add the specified master VAVAILABILITY Component to the instance list, expanding it
within the supplied time range. VAVAILABILITY components are not recurring, they have an
@@ -469,7 +501,11 @@ def _addAvailabilityComponent(self, component, lowerLimit, upperlimit):
"""

start = component.getStartDateUTC()
if start is not None and start >= upperlimit:

if start:
lowerLimit, upperLimit = self._setupLimits(start, lowerLimit, upperLimit)

if start is not None and start >= upperLimit:
# If the availability is beyond the end of the range we want, ignore it
return
if start is None:

0 comments on commit 1bc8cc9

Please sign in to comment.
You can’t perform that action at this time.