<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[10744] CalendarServer/trunk/twistedcaldav/instance.py</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/10744">10744</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2013-02-15 14:01:47 -0800 (Fri, 15 Feb 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix boundary case on an expand report with an all-day event.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktwistedcaldavinstancepy">CalendarServer/trunk/twistedcaldav/instance.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktwistedcaldavinstancepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/instance.py (10743 => 10744)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/instance.py        2013-02-15 21:57:55 UTC (rev 10743)
+++ CalendarServer/trunk/twistedcaldav/instance.py        2013-02-15 22:01:47 UTC (rev 10744)
</span><span class="lines">@@ -104,7 +104,10 @@
</span><span class="cx">         self.ignoreInvalidInstances = ignoreInvalidInstances
</span><span class="cx">         self.normalizeFunction = normalizeFunction
</span><span class="cx"> 
</span><ins>+        self.adjustedLowerLimit = None
+        self.adjustedUpperLimit = None
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx">     def __iter__(self):
</span><span class="cx">         # Return keys in sorted order via iterator
</span><span class="cx">         for i in sorted(self.instances.keys()):
</span><span class="lines">@@ -184,6 +187,28 @@
</span><span class="cx">             raise TooManyInstancesError()
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def _setupLimits(self, dt, lowerLimit, upperLimit):
+        &quot;&quot;&quot;
+        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.
+        &quot;&quot;&quot;
+
+        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,)
+
+
</ins><span class="cx">     def _getMasterEventDetails(self, component):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Logic here comes from RFC4791 Section 9.9
</span><span class="lines">@@ -210,7 +235,7 @@
</span><span class="cx">         return (rulestart, start, end, duration,)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def _addMasterEventComponent(self, component, lowerLimit, upperlimit):
</del><ins>+    def _addMasterEventComponent(self, component, lowerLimit, upperLimit):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Add the specified master VEVENT Component to the instance list, expanding it
</span><span class="cx">         within the supplied time range.
</span><span class="lines">@@ -223,10 +248,11 @@
</span><span class="cx">             return
</span><span class="cx">         rulestart, start, end, duration = details
</span><span class="cx"> 
</span><del>-        self._addMasterComponent(component, lowerLimit, upperlimit, rulestart, start, end, duration)
</del><ins>+        lowerLimit, upperLimit = self._setupLimits(start, lowerLimit, upperLimit)
+        self._addMasterComponent(component, lowerLimit, upperLimit, rulestart, start, end, duration)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def _addOverrideEventComponent(self, component, lowerLimit, upperlimit, got_master):
</del><ins>+    def _addOverrideEventComponent(self, component, lowerLimit, upperLimit, got_master):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Add the specified overridden VEVENT Component to the instance list, replacing
</span><span class="cx">         the one generated by the master component.
</span><span class="lines">@@ -241,7 +267,8 @@
</span><span class="cx">             return
</span><span class="cx">         _ignore_rulestart, start, end, _ignore_duration = details
</span><span class="cx"> 
</span><del>-        self._addOverrideComponent(component, lowerLimit, upperlimit, start, end, got_master)
</del><ins>+        lowerLimit, upperLimit = self._setupLimits(start, lowerLimit, upperLimit)
+        self._addOverrideComponent(component, lowerLimit, upperLimit, start, end, got_master)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def _getMasterToDoDetails(self, component):
</span><span class="lines">@@ -290,7 +317,7 @@
</span><span class="cx">         return (rulestart, start, end, duration,)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def _addMasterToDoComponent(self, component, lowerLimit, upperlimit):
</del><ins>+    def _addMasterToDoComponent(self, component, lowerLimit, upperLimit):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Add the specified master VTODO Component to the instance list, expanding it
</span><span class="cx">         within the supplied time range.
</span><span class="lines">@@ -302,10 +329,11 @@
</span><span class="cx">             return
</span><span class="cx">         rulestart, start, end, duration = details
</span><span class="cx"> 
</span><del>-        self._addMasterComponent(component, lowerLimit, upperlimit, rulestart, start, end, duration)
</del><ins>+        lowerLimit, upperLimit = self._setupLimits(start, lowerLimit, upperLimit)
+        self._addMasterComponent(component, lowerLimit, upperLimit, rulestart, start, end, duration)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def _addOverrideToDoComponent(self, component, lowerLimit, upperlimit, got_master):
</del><ins>+    def _addOverrideToDoComponent(self, component, lowerLimit, upperLimit, got_master):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Add the specified overridden VTODO Component to the instance list, replacing
</span><span class="cx">         the one generated by the master component.
</span><span class="lines">@@ -320,7 +348,8 @@
</span><span class="cx">             return
</span><span class="cx">         _ignore_rulestart, start, end, _ignore_duration = details
</span><span class="cx"> 
</span><del>-        self._addOverrideComponent(component, lowerLimit, upperlimit, start, end, got_master)
</del><ins>+        lowerLimit, upperLimit = self._setupLimits(start, lowerLimit, upperLimit)
+        self._addOverrideComponent(component, lowerLimit, upperLimit, start, end, got_master)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def _addMasterComponent(self, component, lowerLimit, upperlimit, rulestart, start, end, duration):
</span><span class="lines">@@ -422,7 +451,7 @@
</span><span class="cx">                 self.addInstance(Instance(component, start, end, originalStart, False, False))
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def _addFreeBusyComponent(self, component, lowerLimit, upperlimit):
</del><ins>+    def _addFreeBusyComponent(self, component, lowerLimit, upperLimit):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Add the specified master VFREEBUSY Component to the instance list, expanding it
</span><span class="cx">         within the supplied time range.
</span><span class="lines">@@ -435,8 +464,11 @@
</span><span class="cx">         if end is None and start is not None:
</span><span class="cx">             raise ValueError(&quot;VFREEBUSY component must have both DTSTART and DTEND: %r&quot; % (component,))
</span><span class="cx"> 
</span><ins>+        if start:
+            lowerLimit, upperLimit = self._setupLimits(start, lowerLimit, upperLimit)
+
</ins><span class="cx">         # If the free busy is beyond the end of the range we want, ignore it
</span><del>-        if start is not None and start &gt;= upperlimit:
</del><ins>+        if start is not None and start &gt;= upperLimit:
</ins><span class="cx">             return
</span><span class="cx"> 
</span><span class="cx">         # If the free busy is before the start of the range we want, ignore it
</span><span class="lines">@@ -450,14 +482,14 @@
</span><span class="cx">             for period in fb.value():
</span><span class="cx">                 # Ignore if period starts after limit
</span><span class="cx">                 period = period.getValue()
</span><del>-                if period.getStart() &gt;= upperlimit:
</del><ins>+                if period.getStart() &gt;= upperLimit:
</ins><span class="cx">                     continue
</span><span class="cx">                 start = self.normalizeFunction(period.getStart())
</span><span class="cx">                 end = self.normalizeFunction(period.getEnd())
</span><span class="cx">                 self.addInstance(Instance(component, start, end))
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def _addAvailabilityComponent(self, component, lowerLimit, upperlimit):
</del><ins>+    def _addAvailabilityComponent(self, component, lowerLimit, upperLimit):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Add the specified master VAVAILABILITY Component to the instance list, expanding it
</span><span class="cx">         within the supplied time range. VAVAILABILITY components are not recurring, they have an
</span><span class="lines">@@ -469,7 +501,11 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         start = component.getStartDateUTC()
</span><del>-        if start is not None and start &gt;= upperlimit:
</del><ins>+
+        if start:
+            lowerLimit, upperLimit = self._setupLimits(start, lowerLimit, upperLimit)
+
+        if start is not None and start &gt;= upperLimit:
</ins><span class="cx">             # If the availability is beyond the end of the range we want, ignore it
</span><span class="cx">             return
</span><span class="cx">         if start is None:
</span></span></pre>
</div>
</div>

</body>
</html>