Ejemplo n.º 1
0
 public function parseRecurrences($event)
 {
     $recurring = new Recurrence($event['RRULE']);
     $exclusions = [];
     $additions = [];
     if (!empty($event['EXDATES'])) {
         foreach ($event['EXDATES'] as $exDate) {
             if (is_array($exDate)) {
                 foreach ($exDate as $singleExDate) {
                     $exclusions[] = $singleExDate->getTimestamp();
                 }
             } else {
                 $exclusions[] = $exDate->getTimestamp();
             }
         }
     }
     if (!empty($event['RDATES'])) {
         foreach ($event['RDATES'] as $rDate) {
             if (is_array($rDate)) {
                 foreach ($rDate as $singleRDate) {
                     $additions[] = $singleRDate->getTimestamp();
                 }
             } else {
                 $additions[] = $rDate->getTimestamp();
             }
         }
     }
     $until = $recurring->getUntil();
     if ($until === false) {
         //forever... limit to 3 years
         $end = clone $event['DTSTART'];
         $end->add(new \DateInterval('P3Y'));
         // + 3 years
         $recurring->setUntil($end);
         $until = $recurring->getUntil();
     }
     date_default_timezone_set($event['DTSTART']->getTimezone()->getName());
     $frequency = new Freq($recurring->rrule, $event['DTSTART']->getTimestamp(), $exclusions, $additions);
     $recurrenceTimestamps = $frequency->getAllOccurrences();
     $recurrences = [];
     foreach ($recurrenceTimestamps as $recurrenceTimestamp) {
         $tmp = new \DateTime("now", $event['DTSTART']->getTimezone());
         $tmp->setTimestamp($recurrenceTimestamp);
         $recurrences[] = $tmp;
     }
     return $recurrences;
 }