diff --git a/gulliver/system/class.xmlform.php b/gulliver/system/class.xmlform.php index 7c81d26d3..e57b0c9b3 100755 --- a/gulliver/system/class.xmlform.php +++ b/gulliver/system/class.xmlform.php @@ -4614,109 +4614,11 @@ class XmlForm_Field_Date extends XmlForm_Field_SimpleText return $this->date_create_from_format($tmp, $value, $withHours); } - function date_parse_from_format($format, $date) { - $returnArray = array('hour' => 0, 'minute' => 0, 'second' => 0, - 'month' => 0, 'day' => 0, 'year' => 0); - - $dateArray = array(); - - // array of valid date codes with keys for the return array as the values - $validDateTimeCode = array('Y' => 'year', 'y' => 'year', - 'm' => 'month', 'n' => 'month', - 'd' => 'day', 'j' => 'day', - 'H' => 'hour', 'G' => 'hour', - 'i' => 'minute', 's' => 'second'); - - /* create an array of valid keys for the return array - * in the order that they appear in $format - */ - for ($i = 0 ; $i <= strlen($format) - 1 ; $i++) { - $char = substr($format, $i, 1); - - if (array_key_exists($char, $validDateTimeCode)) { - $dateArray[$validDateTimeCode[$char]] = ''; - } - } - - // create array of reg ex things for each date part - $regExArray = array('.' => '\.', // escape the period - - // parse d first so we dont mangle the reg ex - // day - 'd' => '(\d{2})', - - // year - 'Y' => '(\d{4})', - 'y' => '(\d{2})', - - // month - 'm' => '(\d{2})', - 'n' => '(\d{1,2})', - - // day - 'j' => '(\d{1,2})', - - // hour - 'H' => '(\d{2})', - 'G' => '(\d{1,2})', - - // minutes - 'i' => '(\d{2})', - - // seconds - 's' => '(\d{2})'); - - // create a full reg ex string to parse the date with - $regEx = str_replace(array_keys($regExArray), - array_values($regExArray), - $format); - - // Parse the date - preg_match("#$regEx#", $date, $matches); - - // some checks... - if (!is_array($matches) || - $matches[0] != $date || - sizeof($dateArray) != (sizeof($matches) - 1)) { - return $returnArray; - } - - // an iterator for the $matches array - $i = 1; - - foreach ($dateArray AS $key => $value) { - $dateArray[$key] = $matches[$i++]; - - if (array_key_exists($key, $returnArray)) { - $returnArray[$key] = $dateArray[$key]; - } - } - - return $returnArray; - } - - function strptime($format, $date) { - $dateArray = array(); - - $dateArray = $this->date_parse_from_format($format, $date); - - if (is_array($dateArray)) { - return mktime($dateArray['hour'], - $dateArray['minute'], - $dateArray['second'], - $dateArray['month'], - $dateArray['day'], - $dateArray['year']); - } else { - return 0; - } - } - function date_create_from_format( $dformat, $dvalue, $withHours = false ) { $schedule = $dvalue; $schedule_format = str_replace(array('Y','m','d','H','M','S'),array('%Y','%m','%d','%H','%M','%S') ,$dformat); - $ugly = $this->strptime($schedule, $schedule_format); + $ugly = strptime($schedule, $schedule_format); $ymd = sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $ugly['tm_year'] + 1900, @@ -6031,3 +5933,31 @@ function masktophp ($mask, $value) return $value; } +if (!function_exists('strptime')) { + function strptime($date, $format) { + $masks = array( + '%d' => '(?P[0-9]{2})', + '%m' => '(?P[0-9]{2})', + '%Y' => '(?P[0-9]{4})', + '%H' => '(?P[0-9]{2})', + '%M' => '(?P[0-9]{2})', + '%S' => '(?P[0-9]{2})', + // usw.. + ); + + $rexep = "#".strtr(preg_quote($format), $masks)."#"; + if(!preg_match($rexep, $date, $out)) { + return false; + } + + $ret = array( + "tm_sec" => (int) isset($out['S']) ? $out['S'] : 0, + "tm_min" => (int) isset($out['M']) ? $out['M'] : 0, + "tm_hour" => (int) isset($out['H']) ? $out['H'] : 0, + "tm_mday" => (int) $out['d'], + "tm_mon" => $out['m'] ? $out['m'] - 1 : 0, + "tm_year" => $out['Y'] > 1900 ? $out['Y'] - 1900 : 0, + ); + return $ret; + } +} \ No newline at end of file