/** * validDate * * convert input parameters to (valid) iCalcreator date in array format (or FALSE) * if $utc=TRUE and $tz = utc offset ([[+/]-]HHmm) input (local) date array + UTC offset * returns ouput in UTC format date * * @author Kjell-Inge Gustafsson <*****@*****.**> * @since 1.x.x - 2007-05-12 * @param mixed $year * @param mixed $month optional * @param int $day optional * @param int $hour optional * @param int $min optional * @param int $sec optional * @param mixed $tz optional * @param bool $utc optional * @return bool false / array $date */ function validDate($year, $month = FALSE, $day = FALSE, $hour = FALSE, $min = FALSE, $sec = FALSE, $tz = FALSE, $utc = FALSE) { $input = array(); $toolbox = new calendarComponent(); $parno = null; if (is_int($year) && is_int($month) && is_int($day)) { $input['year'] = $year; $input['month'] = $month; $input['day'] = $day; if ($hour !== FALSE || $min !== FALSE || $sec !== FALSE) { $parno = 6; if ($hour !== FALSE) { $input['hour'] = $hour; } if ($min !== FALSE) { $input['min'] = $min; } if ($sec !== FALSE) { $input['sec'] = $sec; } } if ($tz !== FALSE) { $parno = 7; $input['tz'] = $tz; } elseif (!$parno) { $parno = 3; } $input = $toolbox->_date_time_array($input, $parno); } elseif (is_array($year) && isset($year['timestamp'])) { $input = $toolbox->_date_time_string(date('Y-m-d H:i:s', $year['timestamp']), 6); $input['tz'] = isset($year['tz']) ? $year['tz'] : null; $utc = TRUE === $month ? TRUE : FALSE; } elseif (is_array($year) && in_array(count($year), array(3, 4, 6, 7))) { if (isset($year['tz']) || 4 == count($year) || 7 == count($year)) { $parno = 7; } elseif (isset($year['hour']) || isset($year['min']) || isset($year['sec']) || 6 == count($year)) { $parno = 6; } else { $parno = 3; } $input = $toolbox->_date_time_array($year, $parno); $utc = TRUE === $month ? TRUE : FALSE; } elseif (8 <= strlen(trim($year))) { // ex. 2006-08-03 10:12:18 $input = $toolbox->_date_time_string($year); $utc = TRUE === $month ? TRUE : FALSE; } else { return FALSE; } if (!checkdate($input['month'], $input['day'], $input['year'])) { return FALSE; } if (isset($input['hour']) && (0 > $input['hour'] || 23 < $input['hour'])) { return FALSE; } if (isset($input['min']) && (0 > $input['min'] || 59 < $input['min'])) { return FALSE; } if (isset($input['sec']) && (0 > $input['sec'] || 59 < $input['sec'])) { return FALSE; } if (isset($input['tz']) && '' < trim($input['tz'])) { $input['tz'] = trim($input['tz']); if (ctype_digit($input['tz'][1])) { // only numeric tz=offset $offset = 0; if (ctype_digit($input['tz'][0])) { $input['tz'] = '+' . $input['tz']; } if (5 == strlen($input['tz']) && '0000' <= substr($input['tz'], -4) && '9999' >= substr($input['tz'], -4) && ('+' == substr($input['tz'], 0, 1) || '-' == substr($input['tz'], 0, 1))) { $hours2sec = substr($input['tz'], 1, 2) * 3600; $min2sec = substr($input['tz'], -2) * 60; $sign = substr($input['tz'], 0, 1); $offset = $sign . '1' * ($hours2sec + $min2sec); } elseif (7 == strlen($input['tz']) && '000000' <= substr($input['tz'], -6) && '999999' >= substr($input['tz'], -6) && ('+' == substr($input['tz'], 0, 1) || '-' == substr($input['tz'], 0, 1))) { $hours2sec = substr($input['tz'], 1, 2) * 3600; $min2sec = substr($input['tz'], 3, 2) * 60; $sec = substr($input['tz'], -2); $sign = substr($input['tz'], 0, 1); $offset = $sign . '1' * ($hours2sec + $min2sec + $sec); } if (0 != $offset) { if (!isset($input['hour'])) { $input['hour'] = 0; } if (!isset($input['min'])) { $input['min'] = 0; } if (!isset($input['sec'])) { $input['sec'] = 0; } $input = date('Y-m-d H:i:s\\Z', mktime($input['hour'], $input['min'], $input['sec'] + $offset, $input['month'], $input['day'], $input['year'])); $parno = $utc ? 7 : 6; $input = $toolbox->_date_time_string($input, $parno); if (!$utc && isset($input['tz']) && 'Z' == $input['tz']) { unset($input['tz']); } } } } return $input; }
/** * validDate * * convert input parameters to (valid) iCalcreator date in array format (or FALSE) * if $utc=TRUE and $tz = utc offset ([[+/]-]HHmm) input (local) date array + UTC offset * returns ouput in UTC format date * * @author Kjell-Inge Gustafsson <*****@*****.**> * @since 2.2.2 - 2007-07-29 * @param mixed $year * @param mixed $month optional * @param int $day optional * @param int $hour optional * @param int $min optional * @param int $sec optional * @param mixed $tz optional * @param bool $utc optional * @return bool false / array $date */ function validDate($year, $month = FALSE, $day = FALSE, $hour = FALSE, $min = FALSE, $sec = FALSE, $tz = FALSE, $utc = FALSE) { $input = array(); $toolbox = new calendarComponent(); $parno = null; if (is_array($year) && isset($year['timestamp'])) { $input = $toolbox->_date_time_string(date('Y-m-d H:i:s', $year['timestamp']), 6); $input['tz'] = isset($year['tz']) ? $year['tz'] : null; $utc = TRUE === $month ? TRUE : FALSE; } elseif (is_array($year) && in_array(count($year), array(3, 4, 6, 7))) { if (isset($year['tz']) || 4 == count($year) || 7 == count($year)) { $parno = 7; } elseif (isset($year['hour']) || isset($year['min']) || isset($year['sec']) || 6 == count($year)) { $parno = 6; } else { $parno = 3; } $input = $toolbox->_date_time_array($year, $parno); $utc = TRUE === $month ? TRUE : FALSE; } elseif (8 <= strlen(trim($year))) { // ex. 2006-08-03 10:12:18 $input = $toolbox->_date_time_string($year); $utc = TRUE === $month ? TRUE : FALSE; } elseif ($year !== FALSE && $month !== FALSE && $day !== FALSE) { if (0 > (int) $year || 2100 < (int) $year) { return FALSE; } $month = (int) $month; if (1 > $month || 12 < $month) { return FALSE; } $day = (int) $day; if (1 > $day || 31 < $day) { return FALSE; } $input['year'] = $year; $input['month'] = $month; $input['day'] = $day; if ($hour !== FALSE || $min !== FALSE || $sec !== FALSE) { $parno = 6; if ($hour !== FALSE) { $input['hour'] = $hour; } if ($min !== FALSE) { $input['min'] = $min; } if ($sec !== FALSE) { $input['sec'] = $sec; } } if ($tz !== FALSE) { $parno = 7; $input['tz'] = $tz; } elseif (!$parno) { $parno = 3; } $input = $toolbox->_date_time_array($input, $parno); } else { return FALSE; } if (!checkdate($input['month'], $input['day'], $input['year'])) { return FALSE; } if (isset($input['hour']) && (0 > $input['hour'] || 23 < $input['hour'])) { return FALSE; } if (isset($input['min']) && (0 > $input['min'] || 59 < $input['min'])) { return FALSE; } if (isset($input['sec']) && (0 > $input['sec'] || 59 < $input['sec'])) { return FALSE; } if (isset($input['tz']) && '' < trim($input['tz'])) { $input['tz'] = (string) trim($input['tz']); if (ctype_digit($input['tz'][1])) { // only numeric tz=offset $offset = 0; if (ctype_digit($input['tz'][0])) { $input['tz'] = '+' . $input['tz']; } $offset = $toolbox->_tz2offset($input['tz']); if (0 != $offset) { if (!isset($input['hour'])) { $input['hour'] = 0; } if (!isset($input['min'])) { $input['min'] = 0; } if (!isset($input['sec'])) { $input['sec'] = 0; } $input = date('Y-m-d H:i:s\\Z', mktime($input['hour'], $input['min'], $input['sec'] + $offset, $input['month'], $input['day'], $input['year'])); $parno = $utc ? 7 : 6; $input = $toolbox->_date_time_string($input, $parno); if (!$utc && isset($input['tz']) && 'Z' == $input['tz']) { unset($input['tz']); } } } } return $input; }