24 include_once(
'./Services/Calendar/classes/class.ilDateList.php');
25 include_once(
'./Services/Calendar/classes/class.ilTimeZone.php');
26 include_once(
'./Services/Calendar/classes/class.ilCalendarUtil.php');
67 $this->
event = $entry;
68 $this->recurrence = $rec;
101 $this->valid_dates->add($this->event->getStart());
117 $this->valid_dates->add($this->event->getStart());
121 $time = microtime(
true);
125 #echo "ZEIT: ADJUST: ".(microtime(true) - $time).'<br>';
134 $this->frequence_context = $this->recurrence->getFrequenceType();
141 #echo "BYMONTH: ".$freq_res;
144 #echo "BYWEEKNO: ".$freq_res;
147 #echo "BYYEARDAY: ".$freq_res;
151 #echo "BYMONTHDAY: ".$freq_res;
153 #$time = microtime(true);
155 #echo "ZEIT: ".(microtime(true) - $time);
156 #echo "BYDAY: ".$freq_res;
160 #echo "BYSETPOS: ".$freq_res;
174 $this->valid_dates->sort();
188 $this->timezone = $this->
event->isFullday() ?
ilTimeZone::UTC : $this->recurrence->getTimeZone();
191 $this->period_start = clone $a_start;
192 $this->period_end = clone $a_end;
193 $this->start = clone $this->
event->getStart();
197 if($this->event->isFullday())
205 $this->period_start->switchTimeZone($this->recurrence->getTimeZone());
206 $this->period_end->switchTimeZone($this->recurrence->getTimeZone());
207 $this->start->switchTimeZone($this->recurrence->getTimeZone());
213 $this->log->write(__METHOD__.
': '.$e->getMessage());
225 $time = microtime(
true);
229 if($this->recurrence->getFrequenceUntilCount() > 0)
237 $optimized = clone
$start;
253 switch($this->recurrence->getFrequenceType())
272 $ilLog->write(__METHOD__.
'No frequence defined.');
287 if(!$this->recurrence->getBYMONTHList())
292 foreach($list->
get() as $date)
294 #echo "SEED: ".$seed;
296 foreach($this->recurrence->getBYMONTHList() as $month)
298 #echo "RULW_MONTH:".$month;
307 #echo "BYMONTH: ".$month_date;
308 $month_list->add($month_date);
312 $month_list->add($date);
337 if(!$this->recurrence->getBYWEEKNOList())
342 foreach($list->
get() as $seed)
344 $weeks_in_year = date(
'W',mktime(0,0,0,12,28,$seed->get(
IL_CAL_FKT_DATE,
'Y',$this->timezone)));
345 $this->log->write(__METHOD__.
': Year '.$seed->get(
IL_CAL_FKT_DATE,
'Y',$this->timezone).
' has '.$weeks_in_year.
' weeks');
346 foreach($this->recurrence->getBYWEEKNOList() as $week_no)
348 $week_no = $week_no < 0 ? ($weeks_in_year + $week_no + 1) : $week_no;
350 switch($this->frequence_context)
353 $this->log->write(__METHOD__.
': Handling BYWEEKNO in MONTHLY context');
357 $weeks_list->add($seed);
362 $this->log->write(__METHOD__.
': Handling BYWEEKNO in YEARLY context');
363 $week_diff = $week_no - $seed->get(
IL_CAL_FKT_DATE,
'W',$this->timezone);
368 $weeks_list->add($new_week);
386 if(!$this->recurrence->getBYYEARDAYList())
391 foreach($list->
get() as $seed)
393 $num_days = date(
'z',mktime(0,0,0,12,31,$seed->get(
IL_CAL_FKT_DATE,
'Y',$this->timezone)));
394 $this->log->write(__METHOD__.
': Year '.$seed->get(
IL_CAL_FKT_DATE,
'Y',$this->timezone).
' has '.$num_days.
' days.');
396 foreach($this->recurrence->getBYYEARDAYList() as $day_no)
398 $day_no = $day_no < 0 ? ($num_days + $day_no + 1) : $day_no;
404 switch($this->frequence_context)
410 $days_list->add($new_day);
417 $days_list->add($new_day);
424 $days_list->add($new_day);
429 $day_list->add($new_day);
447 if(!$this->recurrence->getBYMONTHDAYList())
452 foreach($list->
get() as $seed)
462 #$this->log->write(__METHOD__.': Month '.$seed->get(IL_CAL_FKT_DATE,'M',$this->timezone).' has '.$num_days.' days.');
464 foreach($this->recurrence->getBYMONTHDAYList() as $bymonth_no)
466 $day_no = $bymonth_no < 0 ? ($num_days + $bymonth_no + 1) : $bymonth_no;
469 if($day_no < 1 or $day_no > $num_days)
471 $this->log->write(__METHOD__.
': Ignoring BYMONTHDAY rule: '.$day_no.
' for month '.
480 switch($this->frequence_context)
484 #var_dump("<pre>",$seed->get(IL_CAL_FKT_DATE,'z',$this->timezone),$day_no,"</pre>");
487 $days_list->add($new_day);
495 $days_list->add($new_day);
501 $days_list->add($new_day);
505 $h = $this->
event->isFullday() ? 0 : $seed->get(
IL_CAL_FKT_DATE,
'H',$this->timezone);
506 $i = $this->
event->isFullday() ? 0 : $seed->get(
IL_CAL_FKT_DATE,
'i',$this->timezone);
507 $s = $this->
event->isFullday() ? 0 : $seed->get(
IL_CAL_FKT_DATE,
's',$this->timezone);
511 for($month = 1;$month <= 12;$month++)
513 #$num_days = cal_days_in_month(CAL_GREGORIAN,
519 $day_no = $bymonth_no < 0 ? ($num_days + $bymonth_no + 1) : $bymonth_no;
520 if($day_no < 1 or $day_no > $num_days)
522 $this->log->write(__METHOD__.
': Ignoring BYMONTHDAY rule: '.$day_no.
' for month '.$month);
528 $unix = mktime($h,$i,$s,$month,$day_no,
$y);
529 $tz_obj->restoreTZ();
531 $days_list->add($new_day);
553 if(!$this->recurrence->getBYDAYList())
562 foreach($list->
get() as $seed)
568 $date_info[
'mday'] = 1;
569 $date_info[
'mon'] = 1;
572 switch($this->frequence_context)
579 $day_sequence = $this->
getMonthWeekDays($seed_info[
'year'],$seed_info[
'mon']);
589 $day_sequence[strtoupper(substr($seed->get(
IL_CAL_FKT_DATE,
'D'),0,2))] = array($seed_info[
'yday']);
593 foreach($this->recurrence->getBYDAYList() as $byday)
596 $day = strtoupper(substr($byday,-2));
597 $num_by_day = (int) $byday;
603 if(isset($day_sequence[$day][$num_by_day - 1]))
605 $year_day = array($day_sequence[$day][$num_by_day - 1]);
610 if(isset($day_sequence[$day][count($day_sequence[$day]) + $num_by_day]))
612 $year_day = array($day_sequence[$day][count($day_sequence[$day]) + $num_by_day]);
618 if(isset($day_sequence[$day]))
620 $year_day = $day_sequence[$day];
623 foreach($year_day as $day)
625 switch($this->frequence_context)
633 $days_list->add($tmp_date);
652 $time = microtime(
true);
654 $year_days = array();
659 $days = array(0 =>
'SU',1 =>
'MO',2 =>
'TU',3 =>
'WE',4 =>
'TH',5 =>
'FR',6 =>
'SA');
660 for($i = 0;$i < $offset;$i++)
666 for($i = 0;$i < $num_days;$i++)
668 if(($current_day = current($days)) ==
false)
670 $current_day = reset($days);
672 $year_days[$current_day][] = $i;
687 static $month_days = array();
689 if(isset($month_days[$year][$month]))
691 return $month_days[$year][$month];
694 $month_str = $month < 10 ? (
'0'.$month) : $month;
698 $days = array(0 =>
'SU',1 =>
'MO',2 =>
'TU',3 =>
'WE',4 =>
'TH',5 =>
'FR',6 =>
'SA');
699 for($i = 0;$i < $begin_month_info[
'wday'];$i++)
705 if(($current_day = current($days)) ==
false)
707 $current_day = reset($days);
709 $month_days[$year][$month][$current_day][] = $i;
712 return $month_days[$year][$month];
724 $days = array(0 =>
'SU',1 =>
'MO',2 =>
'TU',3 =>
'WE',4 =>
'TH',5 =>
'FR',6 =>
'SA');
726 $start_day = $seed_info[
'yday'] - $seed_info[
'wday'];
727 foreach($days as $num => $day)
729 $week_days[$day][] = $start_day++;
745 if(!$this->recurrence->getBYSETPOSList())
751 $candidates = $list->
get();
752 $candidates_count = count($candidates);
753 foreach($this->recurrence->getBYSETPOSList() as $position)
755 if($position > 0 and $date = $list->
getAtPosition($position))
757 $pos_list->add($date);
759 if($position < 0 and $date = $list->getAtPosition($candidates_count + $position + 1))
761 $pos_list->add($date);
779 foreach($list->
get() as $check_date)
783 $list->
remove($check_date);
789 if($this->recurrence->getFrequenceUntilCount())
794 if(count($this->valid_dates->get()) < $this->recurrence->getFrequenceUntilCount())
796 $this->valid_dates->add(
$res);
800 $this->limit_reached =
true;
806 elseif($this->recurrence->getFrequenceUntilDate())
808 $date = $this->recurrence->getFrequenceUntilDate();
813 $this->limit_reached =
true;
816 $this->valid_dates->add(
$res);
820 $this->valid_dates->merge($list);
831 if(!$this->recurrence->getExclusionDates())
835 foreach($this->recurrence->getExclusionDates() as $excl)
837 $this->valid_dates->removeByDAY($excl->getDate());
858 if($this->event->isFullday())
860 return new ilDate($a_date,$a_format_type);
865 return new ilDateTime($a_date,$a_format_type,$this->timezone);
877 return $this->recurrence->validate();