/**
  * ensures internal duration format for input in string format
  *
  * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**>
  * @since 2.0.5 - 2007-03-14
  * @param string $duration
  * @return array
  */
 public static function _duration_string($duration)
 {
     $duration = (string) trim($duration);
     while ('P' != strtoupper(substr($duration, 0, 1))) {
         if (0 < strlen($duration)) {
             $duration = substr($duration, 1);
         } else {
             return false;
         }
         // no leading P !?!?
     }
     $duration = substr($duration, 1);
     // skip P
     $duration = str_replace('t', 'T', $duration);
     $duration = str_replace('T', '', $duration);
     $output = array();
     $val = null;
     for ($ix = 0; $ix < strlen($duration); $ix++) {
         switch (strtoupper(substr($duration, $ix, 1))) {
             case 'W':
                 $output['week'] = $val;
                 $val = null;
                 break;
             case 'D':
                 $output['day'] = $val;
                 $val = null;
                 break;
             case 'H':
                 $output['hour'] = $val;
                 $val = null;
                 break;
             case 'M':
                 $output['min'] = $val;
                 $val = null;
                 break;
             case 'S':
                 $output['sec'] = $val;
                 $val = null;
                 break;
             default:
                 if (!ctype_digit(substr($duration, $ix, 1))) {
                     return false;
                 } else {
                     $val .= substr($duration, $ix, 1);
                 }
         }
     }
     return iCalUtilityFunctions::_duration_array($output);
 }
예제 #2
0
 /**
  * set calendar component property rdate
  *
  * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**>
  * @since 2.5.1 - 2008-11-07
  * @param array $rdates
  * @param array $params, optional
  * @param integer $index, optional
  * @return bool
  */
 function setRdate($rdates, $params = FALSE, $index = FALSE)
 {
     if (empty($rdates)) {
         if ($this->getConfig('allowEmpty')) {
             iCalUtilityFunctions::_setMval($this->rdate, null, $params, FALSE, $index);
             return TRUE;
         } else {
             return FALSE;
         }
     }
     $input = array('params' => iCalUtilityFunctions::_setParams($params, array('VALUE' => 'DATE-TIME')));
     if (in_array($this->objName, array('vtimezone', 'standard', 'daylight'))) {
         unset($input['params']['TZID']);
         $input['params']['VALUE'] = 'DATE-TIME';
     }
     /*  check if PERIOD, if not set */
     if ((!isset($input['params']['VALUE']) || !in_array($input['params']['VALUE'], array('DATE', 'PERIOD'))) && isset($rdates[0]) && is_array($rdates[0]) && 2 == count($rdates[0]) && isset($rdates[0][0]) && isset($rdates[0][1]) && !isset($rdates[0]['timestamp']) && (is_array($rdates[0][0]) && (isset($rdates[0][0]['timestamp']) || iCalUtilityFunctions::_isArrayDate($rdates[0][0])) || is_string($rdates[0][0]) && 8 <= strlen(trim($rdates[0][0]))) && (is_array($rdates[0][1]) || is_string($rdates[0][1]) && 3 <= strlen(trim($rdates[0][1])))) {
         $input['params']['VALUE'] = 'PERIOD';
     }
     /* check 1:st date, upd. $parno (opt) and save ev. timezone **/
     $date = reset($rdates);
     if (isset($input['params']['VALUE']) && 'PERIOD' == $input['params']['VALUE']) {
         // PERIOD
         $date = reset($date);
     }
     iCalUtilityFunctions::_chkdatecfg($date, $parno, $input['params']);
     if (in_array($this->objName, array('vtimezone', 'standard', 'daylight'))) {
         unset($input['params']['TZID']);
     }
     iCalUtilityFunctions::_existRem($input['params'], 'VALUE', 'DATE-TIME');
     // remove default
     foreach ($rdates as $rpix => $theRdate) {
         $inputa = null;
         if (is_array($theRdate)) {
             if (isset($input['params']['VALUE']) && 'PERIOD' == $input['params']['VALUE']) {
                 // PERIOD
                 foreach ($theRdate as $rix => $rPeriod) {
                     if (is_array($rPeriod)) {
                         if (iCalUtilityFunctions::_isArrayTimestampDate($rPeriod)) {
                             // timestamp
                             $inputab = isset($rPeriod['tz']) ? iCalUtilityFunctions::_timestamp2date($rPeriod, $parno) : iCalUtilityFunctions::_timestamp2date($rPeriod, 6);
                         } elseif (iCalUtilityFunctions::_isArrayDate($rPeriod)) {
                             $inputab = 3 < count($rPeriod) ? iCalUtilityFunctions::_date_time_array($rPeriod, $parno) : iCalUtilityFunctions::_date_time_array($rPeriod, 6);
                         } elseif (1 == count($rPeriod) && 8 <= strlen(reset($rPeriod))) {
                             // text-date
                             $inputab = iCalUtilityFunctions::_date_time_string(reset($rPeriod), $parno);
                         } else {
                             // array format duration
                             $inputab = iCalUtilityFunctions::_duration_array($rPeriod);
                         }
                     } elseif (3 <= strlen(trim($rPeriod)) && in_array($rPeriod[0], array('P', '+', '-'))) {
                         if ('P' != $rPeriod[0]) {
                             $rPeriod = substr($rPeriod, 1);
                         }
                         $inputab = iCalUtilityFunctions::_duration_string($rPeriod);
                     } elseif (8 <= strlen(trim($rPeriod))) {
                         // text date ex. 2006-08-03 10:12:18
                         $inputab = iCalUtilityFunctions::_date_time_string($rPeriod, $parno);
                     }
                     if (isset($input['params']['TZID']) || isset($inputab['tz']) && !iCalUtilityFunctions::_isOffset($inputab['tz']) || isset($inputa[0]) && !isset($inputa[0]['tz']) || isset($inputa[0]['tz']) && !iCalUtilityFunctions::_isOffset($inputa[0]['tz'])) {
                         unset($inputab['tz']);
                     }
                     $inputa[] = $inputab;
                 }
             } elseif (iCalUtilityFunctions::_isArrayTimestampDate($theRdate)) {
                 // timestamp
                 $inputa = iCalUtilityFunctions::_timestamp2date($theRdate, $parno);
             } else {
                 // date[-time]
                 $inputa = iCalUtilityFunctions::_date_time_array($theRdate, $parno);
             }
         } elseif (8 <= strlen(trim($theRdate))) {
             // text date ex. 2006-08-03 10:12:18
             $inputa = iCalUtilityFunctions::_date_time_string($theRdate, $parno);
         }
         if (!isset($input['params']['VALUE']) || 'PERIOD' != $input['params']['VALUE']) {
             // no PERIOD
             if (3 == $parno) {
                 unset($inputa['hour'], $inputa['min'], $inputa['sec'], $inputa['tz']);
             } elseif (isset($inputa['tz'])) {
                 $inputa['tz'] = (string) $inputa['tz'];
             }
             if (isset($input['params']['TZID']) || isset($inputa['tz']) && !iCalUtilityFunctions::_isOffset($inputa['tz']) || isset($input['value'][0]) && !isset($input['value'][0]['tz']) || isset($input['value'][0]['tz']) && !iCalUtilityFunctions::_isOffset($input['value'][0]['tz'])) {
                 unset($inputa['tz']);
             }
         }
         $input['value'][] = $inputa;
     }
     if (3 == $parno) {
         $input['params']['VALUE'] = 'DATE';
         unset($input['params']['TZID']);
     }
     iCalUtilityFunctions::_setMval($this->rdate, $input['value'], $input['params'], FALSE, $index);
     return TRUE;
 }