/**
  * set calendar component property trigger
  *
  * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**>
  * @since 2.16.21 - 2013-06-23
  * @param mixed  $year
  * @param mixed  $month
  * @param int    $day
  * @param int    $week
  * @param int    $hour
  * @param int    $min
  * @param int    $sec
  * @param bool   $relatedStart
  * @param bool   $before
  * @param array  $params
  * @uses calendarComponent::getConfig()
  * @uses calendarComponent::$trigger
  * @uses iCalUtilityFunctions::_setParams()
  * @uses iCalUtilityFunctions::_isArrayTimestampDate()
  * @uses iCalUtilityFunctions::_timestamp2date()
  * @uses iCalUtilityFunctions::_strdate2date()
  * @uses iCalUtilityFunctions::_duration2arr()
  * @return bool
  */
 function setTrigger($year, $month = null, $day = null, $week = FALSE, $hour = FALSE, $min = FALSE, $sec = FALSE, $relatedStart = TRUE, $before = TRUE, $params = FALSE)
 {
     if (empty($year) && (empty($month) || is_array($month)) && empty($day) && empty($week) && empty($hour) && empty($min) && empty($sec)) {
         if ($this->getConfig('allowEmpty')) {
             $this->trigger = array('value' => '', 'params' => iCalUtilityFunctions::_setParams($month));
             return TRUE;
         } else {
             return FALSE;
         }
     }
     if (iCalUtilityFunctions::_isArrayTimestampDate($year)) {
         // timestamp UTC
         $params = iCalUtilityFunctions::_setParams($month);
         $date = iCalUtilityFunctions::_timestamp2date($year, 7);
         foreach ($date as $k => $v) {
             ${$k} = $v;
         }
     } elseif (is_array($year) && (is_array($month) || empty($month))) {
         $params = iCalUtilityFunctions::_setParams($month);
         if (!(array_key_exists('year', $year) && array_key_exists('month', $year) && array_key_exists('day', $year))) {
             // when this must be a duration
             if (isset($params['RELATED']) && 'END' == strtoupper($params['RELATED'])) {
                 $relatedStart = FALSE;
             } else {
                 $relatedStart = array_key_exists('relatedStart', $year) && TRUE !== $year['relatedStart'] ? FALSE : TRUE;
             }
             $before = array_key_exists('before', $year) && TRUE !== $year['before'] ? FALSE : TRUE;
         }
         $SSYY = array_key_exists('year', $year) ? $year['year'] : null;
         $month = array_key_exists('month', $year) ? $year['month'] : null;
         $day = array_key_exists('day', $year) ? $year['day'] : null;
         $week = array_key_exists('week', $year) ? $year['week'] : null;
         $hour = array_key_exists('hour', $year) ? $year['hour'] : 0;
         //null;
         $min = array_key_exists('min', $year) ? $year['min'] : 0;
         //null;
         $sec = array_key_exists('sec', $year) ? $year['sec'] : 0;
         //null;
         $year = $SSYY;
     } elseif (is_string($year) && (is_array($month) || empty($month))) {
         // duration or date in a string
         $params = iCalUtilityFunctions::_setParams($month);
         if (in_array($year[0], array('P', '+', '-'))) {
             // duration
             $relatedStart = isset($params['RELATED']) && 'END' == strtoupper($params['RELATED']) ? FALSE : TRUE;
             $before = '-' == $year[0] ? TRUE : FALSE;
             if ('P' != $year[0]) {
                 $year = substr($year, 1);
             }
             $date = iCalUtilityFunctions::_durationStr2arr($year);
         } else {
             // date
             $date = iCalUtilityFunctions::_strdate2date($year, 7);
         }
         unset($year, $month, $day, $date['unparsedtext']);
         if (empty($date)) {
             $sec = 0;
         } else {
             foreach ($date as $k => $v) {
                 ${$k} = $v;
             }
         }
     } else {
         // single values in function input parameters
         $params = iCalUtilityFunctions::_setParams($params);
     }
     if (!empty($year) && !empty($month) && !empty($day)) {
         // date
         $params['VALUE'] = 'DATE-TIME';
         $hour = $hour ? $hour : 0;
         $min = $min ? $min : 0;
         $sec = $sec ? $sec : 0;
         $this->trigger = array('params' => $params);
         $this->trigger['value'] = array('year' => $year, 'month' => $month, 'day' => $day, 'hour' => $hour, 'min' => $min, 'sec' => $sec, 'tz' => 'Z');
         return TRUE;
     } elseif (empty($year) && empty($month) && (!empty($week) || 0 == $week || (!empty($day) || 0 == $day) || (!empty($hour) || 0 == $hour) || (!empty($min) || 0 == $min) || (!empty($sec) || 0 == $sec))) {
         unset($params['RELATED']);
         // set at output creation (END only)
         unset($params['VALUE']);
         // 'DURATION' default
         $this->trigger = array('params' => $params);
         $this->trigger['value'] = array();
         if (!empty($week)) {
             $this->trigger['value']['week'] = $week;
         }
         if (!empty($day)) {
             $this->trigger['value']['day'] = $day;
         }
         if (!empty($hour)) {
             $this->trigger['value']['hour'] = $hour;
         }
         if (!empty($min)) {
             $this->trigger['value']['min'] = $min;
         }
         if (!empty($sec)) {
             $this->trigger['value']['sec'] = $sec;
         }
         if (empty($this->trigger['value'])) {
             $this->trigger['value']['sec'] = 0;
             $before = FALSE;
         } else {
             $this->trigger['value'] = iCalUtilityFunctions::_duration2arr($this->trigger['value']);
         }
         $relatedStart = FALSE !== $relatedStart ? TRUE : FALSE;
         $before = FALSE !== $before ? TRUE : FALSE;
         $this->trigger['value']['relatedStart'] = $relatedStart;
         $this->trigger['value']['before'] = $before;
         return TRUE;
     }
     return FALSE;
 }
 /**
  * convert format for input date (UTC) to internal date with parameters
  *
  * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**>
  * @since 2.11.8 - 2012-01-19
  * @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;
     iCalUtilityFunctions::_strDate2arr($year);
     if (iCalUtilityFunctions::_isArrayDate($year)) {
         $input['value'] = iCalUtilityFunctions::_date_time_array($year, 7);
         $input['params'] = iCalUtilityFunctions::_setParams($month, array('VALUE' => 'DATE-TIME'));
     } elseif (iCalUtilityFunctions::_isArrayTimestampDate($year)) {
         $input['value'] = iCalUtilityFunctions::_timestamp2date($year, 7);
         $input['params'] = iCalUtilityFunctions::_setParams($month, array('VALUE' => 'DATE-TIME'));
     } elseif (8 <= strlen(trim($year))) {
         // ex. 2006-08-03 10:12:18
         $input['value'] = iCalUtilityFunctions::_date_time_string($year, 7);
         unset($input['value']['unparsedtext']);
         $input['params'] = iCalUtilityFunctions::_setParams($month, array('VALUE' => 'DATE-TIME'));
     } else {
         $input['value'] = array('year' => $year, 'month' => $month, 'day' => $day, 'hour' => $hour, 'min' => $min, 'sec' => $sec);
         $input['params'] = iCalUtilityFunctions::_setParams($params, array('VALUE' => 'DATE-TIME'));
     }
     $parno = iCalUtilityFunctions::_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['params']['TZID']) && !empty($input['params']['TZID'])) {
         if ('Z' != $input['params']['TZID'] && iCalUtilityFunctions::_isOffset($input['params']['TZID'])) {
             // utc offset in TZID to tz
             $input['value']['tz'] = $input['params']['TZID'];
             unset($input['params']['TZID']);
         } elseif (in_array(strtoupper($input['params']['TZID']), array('GMT', 'UTC', 'Z'))) {
             // time zone Z
             $input['value']['tz'] = 'Z';
             unset($input['params']['TZID']);
         }
     }
     if (!isset($input['value']['tz']) || !iCalUtilityFunctions::_isOffset($input['value']['tz'])) {
         $input['value']['tz'] = 'Z';
     }
     return $input;
 }
예제 #3
0
 /**
  * convert format for input date (UTC) to internal date with parameters
  *
  * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**>
  * @since 2.14.4 - 2012-10-06
  * @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;
     iCalUtilityFunctions::_strDate2arr($year);
     if (iCalUtilityFunctions::_isArrayDate($year)) {
         $input['value'] = iCalUtilityFunctions::_chkDateArr($year, 7);
         if (isset($input['value']['year']) && 100 > $input['value']['year']) {
             $input['value']['year'] += 2000;
         }
         $input['params'] = iCalUtilityFunctions::_setParams($month, array('VALUE' => 'DATE-TIME'));
         if (isset($input['value']['tz']) && 'Z' != $input['value']['tz'] && iCalUtilityFunctions::_isOffset($input['value']['tz'])) {
             $d = $input['value'];
             $strdate = sprintf('%04d-%02d-%02d %02d:%02d:%02d %s', $d['year'], $d['month'], $d['day'], $d['hour'], $d['min'], $d['sec'], $d['tz']);
             $input['value'] = iCalUtilityFunctions::_strdate2date($strdate, 7);
             unset($input['value']['unparsedtext']);
         }
     } elseif (iCalUtilityFunctions::_isArrayTimestampDate($year)) {
         $year['tz'] = 'UTC';
         $input['value'] = iCalUtilityFunctions::_timestamp2date($year, 7);
         $input['params'] = iCalUtilityFunctions::_setParams($month, array('VALUE' => 'DATE-TIME'));
     } elseif (8 <= strlen(trim($year))) {
         // ex. 2006-08-03 10:12:18
         $input['value'] = iCalUtilityFunctions::_strdate2date($year, 7);
         unset($input['value']['unparsedtext']);
         $input['params'] = iCalUtilityFunctions::_setParams($month, array('VALUE' => 'DATE-TIME'));
     } else {
         $input['value'] = array('year' => $year, 'month' => $month, 'day' => $day, 'hour' => $hour, 'min' => $min, 'sec' => $sec);
         if (isset($tz)) {
             $input['value']['tz'] = $tz;
         }
         if (isset($tz) && iCalUtilityFunctions::_isOffset($tz) || isset($input['params']['TZID']) && iCalUtilityFunctions::_isOffset($input['params']['TZID'])) {
             if (!isset($tz) && isset($input['params']['TZID']) && iCalUtilityFunctions::_isOffset($input['params']['TZID'])) {
                 $input['value']['tz'] = $input['params']['TZID'];
             }
             unset($input['params']['TZID']);
             $strdate = iCalUtilityFunctions::_date2strdate($input['value'], 7);
             $input['value'] = iCalUtilityFunctions::_strdate2date($strdate, 7);
             unset($input['value']['unparsedtext']);
         }
         $input['params'] = iCalUtilityFunctions::_setParams($params, array('VALUE' => 'DATE-TIME'));
     }
     $parno = iCalUtilityFunctions::_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;
     }
     $input['value']['tz'] = 'Z';
     return $input;
 }
 /**
  * convert format for input date (UTC) to internal date with parameters
  *
  * @author Kjell-Inge Gustafsson <*****@*****.**>
  * @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 (iCalUtilityFunctions::_isArrayDate($year)) {
         $input['value'] = iCalUtilityFunctions::_date_time_array($year, 7);
         $input['params'] = iCalUtilityFunctions::_setParams($month, array('VALUE' => 'DATE-TIME'));
     } elseif (iCalUtilityFunctions::_isArrayTimestampDate($year)) {
         $input['value'] = iCalUtilityFunctions::_timestamp2date($year, 7);
         $input['params'] = iCalUtilityFunctions::_setParams($month, array('VALUE' => 'DATE-TIME'));
     } elseif (8 <= strlen(trim($year))) {
         // ex. 2006-08-03 10:12:18
         $input['value'] = iCalUtilityFunctions::_date_time_string($year, 7);
         $input['params'] = iCalUtilityFunctions::_setParams($month, array('VALUE' => 'DATE-TIME'));
     } else {
         $input['value'] = array('year' => $year, 'month' => $month, 'day' => $day, 'hour' => $hour, 'min' => $min, 'sec' => $sec);
         $input['params'] = iCalUtilityFunctions::_setParams($params, array('VALUE' => 'DATE-TIME'));
     }
     $parno = iCalUtilityFunctions::_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']) || !iCalUtilityFunctions::_isOffset($input['value']['tz'])) {
         $input['value']['tz'] = 'Z';
     }
     return $input;
 }