24include_once 
'./Services/Calendar/classes/class.ilCalendarRecurrence.php';
 
   25include_once(
'./Services/Calendar/classes/class.ilDateList.php');
 
   26include_once(
'./Services/Calendar/classes/class.ilTimeZone.php');
 
   27include_once(
'./Services/Calendar/classes/class.ilCalendarUtil.php');
 
   28include_once 
'./Services/Calendar/interfaces/interface.ilCalendarRecurrenceCalculation.php';
 
   67        $this->log = 
$GLOBALS[
'DIC']->logger()->cal();
 
   68        $this->
event = $entry;
 
   69        $this->recurrence = $rec;
 
  109        #               echo $this->event->getStart(); 
  110        #               echo $this->event->getEnd(); 
  117            $this->valid_dates->add($this->event->getStart());
 
  134            $this->valid_dates->add($this->event->getStart());
 
  135            #$this->valid_dates->add($this->event->getStart()); 
  140        $time = microtime(
true);
 
  144        #echo "ZEIT: ADJUST: ".(microtime(true) - $time).'<br>';
 
  152            $this->frequence_context = $this->recurrence->getFrequenceType();
 
  159            #echo "BYMONTH: ".$freq_res;
 
  162            #echo "BYWEEKNO: ".$freq_res;
 
  165            #echo "BYYEARDAY: ".$freq_res;
 
  169            #echo "BYMONTHDAY: ".$freq_res;
 
  171            #$time = microtime(true); 
  173            #echo "ZEIT: ".(microtime(true) - $time);
 
  174            #echo "BYDAY: ".$freq_res;
 
  178            #echo "BYSETPOS: ".$freq_res;
 
  194        $this->valid_dates->sort();
 
  207        foreach (
$list as $start_date) {
 
  208            $end_date = clone $start_date;
 
  219                $this->log->debug(
'Removed invalid date ' . (
string) $start_date . 
' <-> ' . (
string) $end_date);
 
  220                $list->remove($start_date);
 
  232        $this->timezone = $this->
event->isFullday() ? 
ilTimeZone::UTC : $this->recurrence->getTimeZone();
 
  235        $this->period_start = clone $a_start;
 
  236        $this->period_end = clone $a_end;
 
  237        $this->start = clone $this->
event->getStart();
 
  240            if ($this->event->isFullday()) {
 
  245                $this->period_start->switchTimeZone($this->recurrence->getTimeZone());
 
  246                $this->period_end->switchTimeZone($this->recurrence->getTimeZone());
 
  247                $this->start->switchTimeZone($this->recurrence->getTimeZone());
 
  251            $this->log->write(__METHOD__ . 
': ' . $e->getMessage());
 
  263        $time = microtime(
true);
 
  267        if ($this->recurrence->getFrequenceUntilCount() > 0) {
 
  273            $optimized = clone 
$start;
 
  289        switch ($this->recurrence->getFrequenceType()) {
 
  307                $ilLog->write(__METHOD__ . 
'No frequence defined.');
 
  322        if (!$this->recurrence->getBYMONTHList()) {
 
  326        foreach ($list->
get() as $date) {
 
  327            #echo "SEED: ".$seed;
 
  329            foreach ($this->recurrence->getBYMONTHList() as $month) {
 
  330                #echo "RULW_MONTH:".$month;
 
  338                    #echo "BYMONTH: ".$month_date;
 
  339                    $month_list->add($month_date);
 
  340                } elseif ($date->get(
IL_CAL_FKT_DATE, 
'n', $this->timezone) == $month) {
 
  341                    $month_list->add($date);
 
  364        if (!$this->recurrence->getBYWEEKNOList()) {
 
  368        foreach ($list->
get() as $seed) {
 
  369            $weeks_in_year = 
date(
'W', mktime(0, 0, 0, 12, 28, $seed->get(
IL_CAL_FKT_DATE, 
'Y', $this->timezone)));
 
  370            $this->log->write(__METHOD__ . 
': Year ' . $seed->get(
IL_CAL_FKT_DATE, 
'Y', $this->timezone) . 
' has ' . $weeks_in_year . 
' weeks');
 
  371            foreach ($this->recurrence->getBYWEEKNOList() as $week_no) {
 
  372                $week_no = $week_no < 0 ? ($weeks_in_year + $week_no + 1) : $week_no;
 
  374                switch ($this->frequence_context) {
 
  376                        $this->log->write(__METHOD__ . 
': Handling BYWEEKNO in MONTHLY context');
 
  379                            $weeks_list->add($seed);
 
  384                        $this->log->write(__METHOD__ . 
': Handling BYWEEKNO in YEARLY context');
 
  385                        $week_diff = $week_no - $seed->get(
IL_CAL_FKT_DATE, 
'W', $this->timezone);
 
  390                        $weeks_list->add($new_week);
 
  408        if (!$this->recurrence->getBYYEARDAYList()) {
 
  412        foreach ($list->
get() as $seed) {
 
  413            $num_days = 
date(
'z', mktime(0, 0, 0, 12, 31, $seed->get(
IL_CAL_FKT_DATE, 
'Y', $this->timezone)));
 
  414            $this->log->write(__METHOD__ . 
': Year ' . $seed->get(
IL_CAL_FKT_DATE, 
'Y', $this->timezone) . 
' has ' . $num_days . 
' days.');
 
  416            foreach ($this->recurrence->getBYYEARDAYList() as $day_no) {
 
  417                $day_no = $day_no < 0 ? ($num_days + $day_no + 1) : $day_no;
 
  419                $day_diff = $day_no - $seed->get(
IL_CAL_FKT_DATE, 
'z', $this->timezone);
 
  423                switch ($this->frequence_context) {
 
  427                            $days_list->add($new_day);
 
  433                            $days_list->add($new_day);
 
  439                            $days_list->add($new_day);
 
  444                        $day_list->add($new_day);
 
  462        if (!$this->recurrence->getBYMONTHDAYList()) {
 
  466        foreach ($list->
get() as $seed) {
 
  476            #$this->log->write(__METHOD__.': Month '.$seed->get(IL_CAL_FKT_DATE,'M',$this->timezone).' has '.$num_days.' days.'); 
  478            foreach ($this->recurrence->getBYMONTHDAYList() as $bymonth_no) {
 
  479                $day_no = $bymonth_no < 0 ? ($num_days + $bymonth_no + 1) : $bymonth_no;
 
  481                    if ($day_no < 1 or $day_no > $num_days) {
 
  482                        $this->log->write(__METHOD__ . 
': Ignoring BYMONTHDAY rule: ' . $day_no . 
' for month ' .
 
  487                $day_diff = $day_no - $seed->get(
IL_CAL_FKT_DATE, 
'j', $this->timezone);
 
  491                switch ($this->frequence_context) {
 
  494                        #var_dump("<pre>",$seed->get(IL_CAL_FKT_DATE,'z',$this->timezone),$day_no,"</pre>");
 
  496                            $days_list->add($new_day);
 
  503                            $days_list->add($new_day);
 
  509                        $days_list->add($new_day);
 
  513                        $h = $this->
event->isFullday() ? 0 : $seed->get(
IL_CAL_FKT_DATE, 
'H', $this->timezone);
 
  514                        $i = $this->
event->isFullday() ? 0 : $seed->get(
IL_CAL_FKT_DATE, 
'i', $this->timezone);
 
  515                        $s = $this->
event->isFullday() ? 0 : $seed->get(
IL_CAL_FKT_DATE, 
's', $this->timezone);
 
  519                        for ($month = 1;$month <= 12;$month++) {
 
  520                            #$num_days = cal_days_in_month(CAL_GREGORIAN, 
  527                            $day_no = $bymonth_no < 0 ? ($num_days + $bymonth_no + 1) : $bymonth_no;
 
  528                            if ($day_no < 1 or $day_no > $num_days) {
 
  529                                $this->log->write(__METHOD__ . 
': Ignoring BYMONTHDAY rule: ' . $day_no . 
' for month ' . $month);
 
  533                                $unix = mktime(
$h, 
$i, 
$s, $month, $day_no, 
$y);
 
  534                                $tz_obj->restoreTZ();
 
  536                                $days_list->add($new_day);
 
  558        if (!$this->recurrence->getBYDAYList()) {
 
  566        foreach ($list->
get() as $seed) {
 
  571            $date_info[
'mday'] = 1;
 
  572            $date_info[
'mon'] = 1;
 
  575            switch ($this->frequence_context) {
 
  581                    $day_sequence = $this->
getMonthWeekDays($seed_info[
'year'], $seed_info[
'mon']);
 
  591                    $day_sequence[strtoupper(substr($seed->get(
IL_CAL_FKT_DATE, 
'D'), 0, 2))] = array($seed_info[
'yday']);
 
  595            foreach ($this->recurrence->getBYDAYList() as $byday) {
 
  597                $day =  strtoupper(substr($byday, -2));
 
  598                $num_by_day = (int) $byday;
 
  601                    if ($num_by_day > 0) {
 
  602                        if (isset($day_sequence[$day][$num_by_day - 1])) {
 
  603                            $year_day =  array($day_sequence[$day][$num_by_day - 1]);
 
  606                        if (isset($day_sequence[$day][count($day_sequence[$day]) + $num_by_day])) {
 
  607                            $year_day = array($day_sequence[$day][count($day_sequence[$day]) + $num_by_day]);
 
  611                    if (isset($day_sequence[$day])) {
 
  612                        $year_day = $day_sequence[$day];
 
  615                foreach ($year_day as $day) {
 
  616                    switch ($this->frequence_context) {
 
  623                            $days_list->add($tmp_date);
 
  641        $time = microtime(
true);
 
  643        $year_days = array();
 
  648        $days = array(0 => 
'SU',1 => 
'MO',2 => 
'TU',3 => 
'WE',4 => 
'TH',5 => 
'FR',6 => 
'SA');
 
  649        for (
$i = 0;
$i < $offset;
$i++) {
 
  654        for (
$i = 0;
$i < $num_days;
$i++) {
 
  655            if (($current_day = current($days)) == 
false) {
 
  656                $current_day = reset($days);
 
  658            $year_days[$current_day][] = 
$i;
 
  673        static $month_days = array();
 
  675        if (isset($month_days[$year][$month])) {
 
  676            return $month_days[$year][$month];
 
  679        $month_str = $month < 10 ? (
'0' . $month) : $month;
 
  683        $days = array(0 => 
'SU',1 => 
'MO',2 => 
'TU',3 => 
'WE',4 => 
'TH',5 => 
'FR',6 => 
'SA');
 
  684        for (
$i = 0;
$i < $begin_month_info[
'wday'];
$i++) {
 
  688            if (($current_day = current($days)) == 
false) {
 
  689                $current_day = reset($days);
 
  691            $month_days[$year][$month][$current_day][] = 
$i;
 
  694        return $month_days[$year][$month];
 
  706        $days = array(0 => 
'SU',1 => 
'MO',2 => 
'TU',3 => 
'WE',4 => 
'TH',5 => 
'FR',6 => 
'SA');
 
  708        $start_day = $seed_info[
'yday'] - $seed_info[
'wday'];
 
  709        foreach ($days as $num => $day) {
 
  710            $week_days[$day][] = $start_day++;
 
  726        if (!$this->recurrence->getBYSETPOSList()) {
 
  731        $candidates = 
$list->get();
 
  732        $candidates_count = count($candidates);
 
  733        foreach ($this->recurrence->getBYSETPOSList() as $position) {
 
  734            if ($position > 0 and $date = 
$list->getAtPosition($position)) {
 
  735                $pos_list->add($date);
 
  737            if ($position < 0 and $date = $list->getAtPosition($candidates_count + $position + 1)) {
 
  738                $pos_list->add($date);
 
  760        foreach (
$list->get() as $check_date) {
 
  762                $this->log->debug(
'Removed invalid date: ' . (
string) $check_date . 
' before starting date:  ' . (
string) $this->event->getStart());
 
  763                $list->remove($check_date);
 
  767        #echo 'Until date '.$this->recurrence->getFrequenceUntilDate(); 
  770        if ($this->recurrence->getFrequenceUntilCount()) {
 
  773                if (count($this->valid_dates->get()) < $this->recurrence->getFrequenceUntilCount()) {
 
  774                    $this->valid_dates->add(
$res);
 
  776                    $this->limit_reached = 
true;
 
  781        } elseif ($this->recurrence->getFrequenceUntilDate()) {
 
  782            #echo 'Until date '.$this->recurrence->getFrequenceUntilDate(); 
  783            $date = $this->recurrence->getFrequenceUntilDate();
 
  785                #echo 'Check date '.$res; 
  787                    #echo 'Limit reached'; 
  788                    $this->limit_reached = 
true;
 
  791                $this->valid_dates->add(
$res);
 
  796        $this->valid_dates->merge(
$list);
 
  807        if (!$this->recurrence->getExclusionDates()) {
 
  810        foreach ($this->recurrence->getExclusionDates() as $excl) {
 
  811            $this->valid_dates->removeByDAY($excl->getDate());
 
  832        if ($this->event->isFullday()) {
 
  833            return new ilDate($a_date, $a_format_type);
 
  836            return new ilDateTime($a_date, $a_format_type, $this->timezone);
 
  848        return $this->recurrence->validate();
 
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
An exception for terminatinating execution or to throw for unit testing.
Calculates an ilDateList for a given calendar entry and recurrence rule.
getMonthWeekDays($year, $month)
get a list of month days
validateRecurrence()
validate recurrence
createDate($a_date, $a_format_type=IL_CAL_UNIX)
create date
applyBYMONTHDAYRules(ilDateList $list)
Apply BYMONTHDAY rules.
__construct(ilDatePeriod $entry, ilCalendarRecurrenceCalculation $rec)
@access public
applyBYSETPOSRules(ilDateList $list)
Apply BYSETPOST rules.
applyBYMONTHRules(ilDateList $list)
Apply BYMONTH rules.
applyBYYEARDAYRules(ilDateList $list)
Apply BYYEARDAY rules.
getYearWeekDays(ilDateTime $seed)
get a list of year week days according to the BYMONTH rule
incrementByFrequency($start)
increment starting time by frequency
calculateDateListByMonth($a_month, $a_year)
calculate day list by month(s) uses a cache of calculated recurring events @access public
calculateDateList(ilDateTime $a_start, ilDateTime $a_end, $a_limit=-1)
calculate date list
initDateList()
init date list
applyLimits(ilDateList $list)
Apply limits (count or until)
adjustTimeZones(ilDateTime $a_start, ilDateTime $a_end)
Adjust timezone.
getWeekWeekDays($seed_info)
get weedays of week
applyBYWEEKNORules(ilDateList $list)
Apply BYWEEKNO rules (1 to 53 and -1 to -53).
getDuration()
Get duration of event.
optimizeStartingTime()
optimize starting time
applyDurationPeriod(ilDateList $list, ilDateTime $start, ilDateTime $end)
Apply duration period.
applyBYDAYRules(ilDateList $list)
Apply BYDAY rules.
static _getMaxDayOfMonth($a_year, $a_month)
get max day of month 2008,2 => 29
static _isLeapYear($a_year)
check if a given year is a leap year
Class for DateTime exceptions.
@classDescription Date and time handling
static _equals(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
Check if two date are equal.
switchTimeZone($a_timezone_identifier='')
Switch timezone.
static _after(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
get($a_format, $a_format_str='', $a_tz='')
get formatted date
static _before(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
static _restoreDefaultTimeZone()
restore default timezone to server timezone
static _setDefaultTimeZone($a_tz)
set default timezone
static _getInstance($a_tz='')
get instance by timezone
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
getEnd()
Interface method get end.
getStart()
Interface method get start.
if(isset($_REQUEST['delete'])) $list
foreach($_POST as $key=> $value) $res