[dev] patch for vfreebusy.php

Amith Varghese amith at xalan.com
Fri Feb 7 09:28:08 PST 2003


After researching Attendee availability some more, I found out that the reason
why Attendee Availability was not display correctly was because the
getFreePeriods method in vfreebusy.php was using an incorrect algorithm to
determine what free periods existed.  I went ahead and change it (and added lots
of comments to explain what I was doing).   Now the Attendee availability seems
to be working correctly.  Please let me know if there are any problems.

Amith

-------------- next part --------------
Index: lib/iCalendar/vfreebusy.php
===================================================================
RCS file: /repository/horde/lib/iCalendar/vfreebusy.php,v
retrieving revision 1.4
diff -u -r1.4 vfreebusy.php
--- lib/iCalendar/vfreebusy.php	22 Jan 2003 04:03:52 -0000	1.4
+++ lib/iCalendar/vfreebusy.php	7 Feb 2003 08:18:09 -0000
@@ -113,20 +113,47 @@
     function getFreePeriods($startStamp, $endStamp)
     {
         $this->simplify();
-        
+
         $periods = array();
         if ($this->getEnd() < $startStamp || $this->getStart() > $endStamp || count($this->_busyPeriods) == 0) {
             return $periods;
         }
-        
-        $nextstart = max($startStamp, $this->getStart());
+
+        // What is done here is that we need to find the first time to start
+        // from.  If all busy periods are after the startStamp, then the first
+        // free period starts at the startStamp.  However if the the first busy
+        // period starts before the startStamp we need to look at the end of
+        // that busy period.  If that end is still before the startStamp we
+        // goto the next busy period.  In the case that the busy period overlaps
+        // the startStamp, we use the end of the busy period as the first time
+        // used for the free period.
+        foreach ($this->_busyPeriods as $start => $end) {
+            if ($start > $startStamp) {
+                $nextstart = $startStamp;
+                break;
+            } else {
+                if ($end > $startStamp) {
+                    $nextstart = $end;
+                    break;
+                }
+            }
+        }
+
+        // Here we look at each busy period and if the period started after the
+        // the startStamp then we use the start of the busy period as the end of
+        // the free period.  The end of that busy period now becomes the next
+        // start of the next free period.  We loop until there are no more busy
+        // periods left between startStamp and endStamp 
         foreach ($this->_busyPeriods as $start => $end) {
-            if ($start <= $endStamp && $end >= $nextstart) {
+            if ($start <= $endStamp && $end >= $nextstart
+                    && $start >= $startStamp) {
                 $periods[$nextstart] = $start;
                 $nextstart = $end;
             }    
         }
 
+        // In case the end of a busy period overlaps the endStamp, we use the
+        // endStamp as the end of our last free period
         if ($nextstart < $endStamp) {
             $periods[$nextstart] = $endStamp;
         }    


More information about the dev mailing list