public function overlaps(TimeRange $range)
 {
     if ($range->get_start() >= $this->end) {
         return FALSE;
     } elseif ($range->get_end() <= $this->start) {
         return FALSE;
     } else {
         return TRUE;
     }
 }
Exemplo n.º 2
0
 public static function formatDateRange(TimeRange $range, $dateStyle, $timeStyle)
 {
     $string = '';
     if ($range instanceof DayRange) {
         $timeStyle = self::NO_STYLE;
     }
     $string = self::formatDate($range->get_start(), $dateStyle, $timeStyle);
     if ($range->get_end() && $range->get_end() != $range->get_start()) {
         if (date('Ymd', $range->get_start()) == date('Ymd', $range->get_end())) {
             $dateStyle = self::NO_STYLE;
         }
         if ($dateStyle != self::NO_STYLE || $timeStyle != self::NO_STYLE) {
             $string .= ($dateStyle ? ' - ' : '-') . self::formatDate($range->get_end(), $dateStyle, $timeStyle);
         }
     }
     return $string;
 }
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;
 }