Ejemplo n.º 1
0
 /**
  * convert format for input date (UTC) to internal date with parameters
  *
  * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**>
  * @since 2.4.17 - 2008-10-31
  * @param mixed $year
  * @param mixed $month optional
  * @param int $day optional
  * @param int $hour optional
  * @param int $min optional
  * @param int $sec optional
  * @param array $params optional
  * @return array
  */
 public static function _setDate2($year, $month = FALSE, $day = FALSE, $hour = FALSE, $min = FALSE, $sec = FALSE, $params = FALSE)
 {
     $input = null;
     if (iCal_UtilityFunctions::_isArrayDate($year)) {
         $input['value'] = iCal_UtilityFunctions::_date_time_array($year, 7);
         $input['params'] = iCal_UtilityFunctions::_setParams($month, array('VALUE' => 'DATE-TIME'));
     } elseif (iCal_UtilityFunctions::_isArrayTimestampDate($year)) {
         $input['value'] = iCal_UtilityFunctions::_timestamp2date($year, 7);
         $input['params'] = iCal_UtilityFunctions::_setParams($month, array('VALUE' => 'DATE-TIME'));
     } elseif (8 <= strlen(trim($year))) {
         // ex. 2006-08-03 10:12:18
         $input['value'] = iCal_UtilityFunctions::_date_time_string($year, 7);
         $input['params'] = iCal_UtilityFunctions::_setParams($month, array('VALUE' => 'DATE-TIME'));
     } else {
         $input['value'] = array('year' => $year, 'month' => $month, 'day' => $day, 'hour' => $hour, 'min' => $min, 'sec' => $sec);
         $input['params'] = iCal_UtilityFunctions::_setParams($params, array('VALUE' => 'DATE-TIME'));
     }
     $parno = iCal_UtilityFunctions::_existRem($input['params'], 'VALUE', 'DATE-TIME', 7);
     // remove default
     if (!isset($input['value']['hour'])) {
         $input['value']['hour'] = 0;
     }
     if (!isset($input['value']['min'])) {
         $input['value']['min'] = 0;
     }
     if (!isset($input['value']['sec'])) {
         $input['value']['sec'] = 0;
     }
     if (!isset($input['value']['tz']) || !iCal_UtilityFunctions::_isOffset($input['value']['tz'])) {
         $input['value']['tz'] = 'Z';
     }
     return $input;
 }
Ejemplo n.º 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')) {
             iCal_UtilityFunctions::_setMval($this->rdate, null, $params, FALSE, $index);
             return TRUE;
         } else {
             return FALSE;
         }
     }
     $input = array('params' => iCal_UtilityFunctions::_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']) || iCal_UtilityFunctions::_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);
     }
     iCal_UtilityFunctions::_chkdatecfg($date, $parno, $input['params']);
     if (in_array($this->objName, array('vtimezone', 'standard', 'daylight'))) {
         unset($input['params']['TZID']);
     }
     iCal_UtilityFunctions::_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 (iCal_UtilityFunctions::_isArrayTimestampDate($rPeriod)) {
                             // timestamp
                             $inputab = isset($rPeriod['tz']) ? iCal_UtilityFunctions::_timestamp2date($rPeriod, $parno) : iCal_UtilityFunctions::_timestamp2date($rPeriod, 6);
                         } elseif (iCal_UtilityFunctions::_isArrayDate($rPeriod)) {
                             $inputab = 3 < count($rPeriod) ? iCal_UtilityFunctions::_date_time_array($rPeriod, $parno) : iCal_UtilityFunctions::_date_time_array($rPeriod, 6);
                         } elseif (1 == count($rPeriod) && 8 <= strlen(reset($rPeriod))) {
                             // text-date
                             $inputab = iCal_UtilityFunctions::_date_time_string(reset($rPeriod), $parno);
                         } else {
                             // array format duration
                             $inputab = iCal_UtilityFunctions::_duration_array($rPeriod);
                         }
                     } elseif (3 <= strlen(trim($rPeriod)) && in_array($rPeriod[0], array('P', '+', '-'))) {
                         if ('P' != $rPeriod[0]) {
                             $rPeriod = substr($rPeriod, 1);
                         }
                         $inputab = iCal_UtilityFunctions::_duration_string($rPeriod);
                     } elseif (8 <= strlen(trim($rPeriod))) {
                         // text date ex. 2006-08-03 10:12:18
                         $inputab = iCal_UtilityFunctions::_date_time_string($rPeriod, $parno);
                     }
                     if (isset($input['params']['TZID']) || isset($inputab['tz']) && !iCal_UtilityFunctions::_isOffset($inputab['tz']) || isset($inputa[0]) && !isset($inputa[0]['tz']) || isset($inputa[0]['tz']) && !iCal_UtilityFunctions::_isOffset($inputa[0]['tz'])) {
                         unset($inputab['tz']);
                     }
                     $inputa[] = $inputab;
                 }
             } elseif (iCal_UtilityFunctions::_isArrayTimestampDate($theRdate)) {
                 // timestamp
                 $inputa = iCal_UtilityFunctions::_timestamp2date($theRdate, $parno);
             } else {
                 // date[-time]
                 $inputa = iCal_UtilityFunctions::_date_time_array($theRdate, $parno);
             }
         } elseif (8 <= strlen(trim($theRdate))) {
             // text date ex. 2006-08-03 10:12:18
             $inputa = iCal_UtilityFunctions::_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']) && !iCal_UtilityFunctions::_isOffset($inputa['tz']) || isset($input['value'][0]) && !isset($input['value'][0]['tz']) || isset($input['value'][0]['tz']) && !iCal_UtilityFunctions::_isOffset($input['value'][0]['tz'])) {
                 unset($inputa['tz']);
             }
         }
         $input['value'][] = $inputa;
     }
     if (3 == $parno) {
         $input['params']['VALUE'] = 'DATE';
         unset($input['params']['TZID']);
     }
     iCal_UtilityFunctions::_setMval($this->rdate, $input['value'], $input['params'], FALSE, $index);
     return TRUE;
 }