Horde_Icalendar_Vfreebusy::getFreePeriods PHP Method

getFreePeriods() public method

Returns all the free periods of time in a given period.
public getFreePeriods ( integer $startStamp, integer $endStamp ) : array
$startStamp integer The start timestamp.
$endStamp integer The end timestamp.
return array A hash with free time periods, the start times as the keys and the end times as the values.
    public function getFreePeriods($startStamp, $endStamp)
    {
        $this->simplify();
        $periods = array();
        // Check that we have data for some part of this period.
        if ($this->getEnd() < $startStamp || $this->getStart() > $endStamp) {
            return $periods;
        }
        // Locate the first time in the requested period we have data for.
        $nextstart = max($startStamp, $this->getStart());
        // Check each busy period and add free periods in between.
        foreach ($this->_busyPeriods as $start => $end) {
            if ($start <= $endStamp && $end >= $nextstart) {
                if ($nextstart <= $start) {
                    $periods[$nextstart] = min($start, $endStamp);
                }
                $nextstart = min($end, $endStamp);
            }
        }
        // If we didn't read the end of the requested period but still have
        // data then mark as free to the end of the period or available data.
        if ($nextstart < $endStamp && $nextstart < $this->getEnd()) {
            $periods[$nextstart] = min($this->getEnd(), $endStamp);
        }
        return $periods;
    }