Exemplo n.º 1
0
 /**
  * Benchmarking getDays function.
  */
 public function testGetDays()
 {
     $timerange = new TimeRange('1975-01-01', '2013-01-01');
     $timerange2 = new TimeRange('2012-01-01', '2012-01-01');
     $overlap_found = false;
     foreach ($timerange->getDays(1, TimeRange::FORWARD) as $date) {
         if ($timerange2->overlaps($date)) {
             $overlap_found = true;
         }
     }
     $this->assertTrue($overlap_found);
 }
Exemplo n.º 2
0
 public function getEventsInRange(TimeRange $range = null, $limit = null, $filters = null)
 {
     $events = array();
     $filters = is_array($filters) ? $filters : array();
     foreach ($this->events as $event) {
         if ($event->filterItem($filters) && $range->overlaps($event->getRange())) {
             $events[] = $event;
         }
     }
     usort($events, array($this, "sort_events"));
     // in some case, it doesn't work properly if we just sort $this->eventStartTimes
     return $events;
 }
Exemplo n.º 3
0
 function occurrences(ICalEvent $event, TimeRange $range = null, $max = null)
 {
     $occurrences = array();
     $time = $event->get_start();
     $diff = $event->get_end() - $event->get_start();
     $limitType = $this->limitType;
     $limit = $this->limit;
     $count = 0;
     //    echo date('m/d/Y H:i:s', $time) . "<br>\n";
     $time = $this->nextIncrement($time, $this->type, $this->interval);
     while ($time <= $range->get_end()) {
         //      echo date('m/d/Y H:i:s', $time) . "<br>\n";
         if ($limitType == 'UNTIL' && $time > $limit) {
             break;
         }
         $occurrence_range = new TimeRange($time, $time + $diff);
         if ($occurrence_range->overlaps($range)) {
             if ($recurrence_exception = $event->getRecurrenceException($time)) {
                 $occurrence = clone $recurrence_exception;
             } else {
                 $occurrence = clone $event;
                 $occurrence->setRange($occurrence_range);
                 $occurrence->clear_rrules();
                 $recurrence_id = strftime("%Y%m%dT%H%M%S", $time);
                 if ($tzid = $occurrence->get_tzid()) {
                     $recurrence_id = sprintf("TZID=%s:%s", $tzid, $recurrence_id);
                 }
                 $occurrence->set_attribute('RECURRENCE-ID', $recurrence_id);
             }
             $occurrences[] = $occurrence;
         }
         if ($limitType == 'COUNT' && $count < $limit) {
             break;
         }
         if ($count > ICalRecurrenceRule::MAX_OCCURRENCES) {
             break;
         }
         if (!is_null($max) && count($occurrences) >= $max) {
             break;
         }
         $time = $this->nextIncrement($time, $this->type, $this->interval);
         $count++;
     }
     return $occurrences;
 }