Exemplo n.º 1
0
 public function calculate($start, $end, array &$obj, TimeIt_Recurrence_Output $out)
 {
     $out->insert(strtotime($obj['startDate']), $obj);
     $dates = explode(',', $obj['repeatSpec']);
     // add all occurrences
     foreach ($dates as $date) {
         $out->insert(strtotime($date), $obj);
     }
 }
Exemplo n.º 2
0
 public function calculate($start, $end, array &$obj, TimeIt_Recurrence_Output $out)
 {
     $ret = array();
     // calculate recurrences
     TimeIt_userapi_icalRruleProzess($ret, $obj, $start, $end);
     // add all recurrences
     foreach (array_keys($ret) as $timestamp) {
         $out->insert($timestamp, $obj);
     }
 }
Exemplo n.º 3
0
 public function calculate($start, $end, array &$obj, TimeIt_Recurrence_Output $out)
 {
     if ($obj['endDate'] == $obj['startDate']) {
         $out->insert(strtotime($obj['startDate']), $obj);
     } else {
         $diff = DateUtil::getDatetimeDiff($obj['startDate'], $obj['endDate']);
         $timestamp = strtotime($obj['startDate']);
         $timestamp = mktime(0, 0, 0, date('n', $timestamp), date('j', $timestamp), date('Y', $timestamp));
         // add days
         for ($i = 0; $i <= $diff['d']; $i++) {
             $out->insert($timestamp, $obj);
             // next day
             $timestamp += 86400;
         }
     }
 }
Exemplo n.º 4
0
 public function insert($timestamp, array &$obj)
 {
     if (!in_array(DateUtil::getDatetime($timestamp, DATEONLYFORMAT_FIXED), $this->_dates)) {
         $this->_out->insert($timestamp, $obj);
     }
 }
Exemplo n.º 5
0
 public function calculate($start, $end, array &$obj, TimeIt_Recurrence_Output $out)
 {
     $time = $start;
     $diff = DateUtil::getDatetimeDiff($obj['startDate'], $time);
     // weekly?
     if ($obj['repeatSpec'] == "week") {
         $weeks = (int) date('W', strtotime($start)) - (int) date('W', strtotime($obj['startDate']));
         $weeks = (int) floor($weeks / $obj['repeatFrec']);
         if ($weeks < 0) {
             $weeks = 0;
         }
         $date = DateUtil::getDatetime(strtotime('+' . $weeks * $obj['repeatFrec'] . ' week', strtotime($obj['startDate'])), DATEONLYFORMAT_FIXED);
         while ($date <= $end && $date <= $obj['endDate']) {
             // in requested range?
             if ($date >= $start && $date <= $end && $date >= $obj['startDate']) {
                 $temp = getDate(strtotime($date));
                 $temp = mktime(0, 0, 0, $temp['mon'], $temp['mday'], $temp['year']);
                 $out->insert($temp, $obj);
             }
             // next occurence
             $weeks++;
             $date = DateUtil::getDatetime(strtotime('+' . $weeks * $obj['repeatFrec'] . ' week', strtotime($obj['startDate'])), DATEONLYFORMAT_FIXED);
         }
         // monthly?
     } else {
         if ($obj['repeatSpec'] == "month") {
             // calc start
             $years = (int) date('Y', strtotime($end)) - (int) date('Y', strtotime($obj['startDate']));
             $months = $years * 12;
             $monthsTemp = (int) date('n', strtotime($start)) - (int) date('n', strtotime($obj['startDate']));
             $months = $months + $monthsTemp;
             $months = (int) floor($months / $obj['repeatFrec']);
             $date = DateUtil::getDatetime(strtotime('+' . $months * $obj['repeatFrec'] . ' month', strtotime($obj['startDate'])), DATEONLYFORMAT_FIXED);
             //print_r($monthsTemp);exit();
             while ($date <= $end && $date <= $obj['endDate']) {
                 // in requested range?
                 if ($date >= $start && $date <= $end && $date >= $obj['startDate']) {
                     $temp = getDate(strtotime($date));
                     $temp = mktime(0, 0, 0, $temp['mon'], $temp['mday'], $temp['year']);
                     $out->insert($temp, $obj);
                 }
                 // next occurence
                 $months++;
                 $date = DateUtil::getDatetime(strtotime('+' . $months * $obj['repeatFrec'] . ' month', strtotime($obj['startDate'])), DATEONLYFORMAT_FIXED);
             }
             // yearly
         } else {
             if ($obj['repeatSpec'] == "year") {
                 $years_start = (int) date('Y', strtotime($obj['startDate']));
                 $years_ende = (int) date('Y', strtotime($obj['endDate']));
                 for ($year = $years_start; $year <= $years_ende; $year += $obj['repeatFrec']) {
                     // calc timestamp
                     $temp = getDate(strtotime($obj['startDate']));
                     $temp = mktime(0, 0, 0, $temp['mon'], $temp['mday'], $year);
                     $date = DateUtil::getDatetime($temp, DATEONLYFORMAT_FIXED);
                     // in requested range?
                     if ($date >= $start && $date <= $end && $date >= $obj['startDate']) {
                         $out->insert($temp, $obj);
                     }
                 }
                 // daily
             } else {
                 $repeats = (int) floor($diff['d'] / $obj['repeatFrec']);
                 $repeats--;
                 if ($repeats < 0) {
                     $daysToLastUnusedRepeat = (int) -$obj['repeatFrec'];
                     /* } else if($repeats == 0)
                        {
                                $daysToLastUnusedRepeat = 0 - $obj['repeatFrec'];*/
                 } else {
                     $daysToLastUnusedRepeat = $repeats * $obj['repeatFrec'];
                 }
                 $timestamp = strtotime($obj['startDate']);
                 $timestampEnd = strtotime($end);
                 $counter = $obj['repeatFrec'];
                 while (true) {
                     $temp = mktime(0, 0, 0, date('n', $timestamp), date('j', $timestamp) + $daysToLastUnusedRepeat + $counter, date('Y', $timestamp));
                     $counter += $obj['repeatFrec'];
                     // end reached?
                     if ($temp > strtotime($obj['endDate']) || $temp > $timestampEnd) {
                         break;
                     }
                     $out->insert($temp, $obj);
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
 public function calculate($start, $end, array &$obj, TimeIt_Recurrence_Output $out)
 {
     // mappings from numbers to strings for strtotime
     $typMap = array(1 => '', 2 => '+ 1 week', 3 => '+ 2 week', 4 => '+ 3 week', 5 => '- 1 week');
     $weekdayMap = array(0 => 'sun', 1 => 'mon', 2 => 'tue', 3 => 'wed', 4 => 'thu', 5 => 'fri', 6 => 'sat');
     $spec = explode(' ', $obj['repeatSpec']);
     $specOld = $spec;
     $specOld[0] = explode(',', $specOld[0]);
     // loop through checked days
     foreach ($specOld[0] as $specValue) {
         $spec[0] = $specValue;
         // calc unix timestamp
         $a = $typMap[(int) $spec[0]];
         $b = $weekdayMap[(int) $spec[1]];
         $c = '';
         // special case
         if ((int) $spec[0] == 5) {
             $temp = explode('-', $start);
             $date = strtotime('+1 month +1 day', mktime(0, 0, 0, (int) $temp[1], 1, (int) $temp[0]));
         } else {
             // normal
             $temp = explode('-', $start);
             $date = mktime(0, 0, 0, (int) $temp[1], 1, (int) $temp[0]);
         }
         $stamp = strtotime($b, $date);
         // special case: secound is used for the time in strtotime
         // emulation with first and the addition of seven days
         if ($a) {
             $stamp = strtotime($a, $stamp);
         }
         $months = 0;
         $date = DateUtil::getDatetime($stamp, DATEONLYFORMAT_FIXED);
         // set helper variable for "date out of range detection"
         if ((int) substr($date, 0, 4) >= 2000) {
             $inYear2000 = true;
         } else {
             $inYear2000 = false;
         }
         while ($date <= $end && $date <= $obj['endDate']) {
             // in requested range?
             if ($date >= $start && $date <= $end && $date >= $obj['startDate']) {
                 $temp1 = getDate(strtotime($date));
                 $temp1 = mktime(0, 0, 0, $temp1['mon'], $temp1['mday'], $temp1['year']);
                 $out->insert($temp1, $obj);
             }
             // next occurence
             $months++;
             // calc unix timestamp
             if ((int) $spec[0] == 5) {
                 // special case: last from strtotime(to the past) != last form TimeIt(to the future)
                 $month_calc = $months * (int) $obj['repeatFrec'] + 1;
             } else {
                 $month_calc = $months * (int) $obj['repeatFrec'];
             }
             $tdate = strtotime('+' . $month_calc . ' month', mktime(0, 0, 0, (int) $temp[1], 1, (int) $temp[0]));
             $stamp = strtotime($b . '' . $a, $tdate);
             $date = DateUtil::getDatetime($stamp, DATEONLYFORMAT_FIXED);
             // detect date out of range: after year 2037 the time jumps back to 1970
             // Stop calculation after a jump
             if ($inYear2000 && (int) substr($date, 0, 4) < 2000) {
                 break;
             } else {
                 if (!$inYear2000 && (int) substr($date, 0, 4) >= 2000) {
                     $inYear2000 = true;
                 }
             }
         }
     }
 }