setCSSClass('datetime'); } public function parseInput($input, $parent) { if(trim($input) == "") return NULL; elseif(preg_match('$([0-9]{2,4})-([0-9]{1,2})-([0-9]{1,2})[tT:]([0-9]{1,2}):([0-9]{1,2})$', $input, $match)) { return new DateTime($input); } elseif(preg_match('$([0-9]{1,2})\\.([0-9]{1,2})\\.([0-9]{1,4})[ ]+([0-9]{1,2}):([0-9]{1,2})(:([0-9]{1,2}))?$', $input, $match)) { // TODO: 5.2 workaround $parse = 'd.m.'; $parse .= (strlen($match[3]) > 2) ? 'Y' : 'y'; $parse .= ' H:i'; $parse .= (isset($match[6]) > 2) ? ':s' : ''; $i = \DateTime::createFromFormat($parse, $input); if(!empty($i)) return $i; throw new \LogicException('datetime format is not parsable'); } else throw new \LogicException('datetime format is invalid'); return $input; } public function generate($parent) { $id = $this->getID(); $name = $this->getName(); $css = $this->getCSSClass(); $system = \MCMS\System::getInstance(); $size = $this->getParam('size', 0); $maxsize = $this->getParam('maxsize', 40); $value = $this->getValue(); $js_import = array(); $js_submit = ''; $html = 'getInlineCSS()) $html .= 'style="' . $this->getInlineCSS() . '" '; if($size > 0) $html .= 'size="' . $size . '" '; if($maxsize > 0) $html .= 'maxlength="' . $maxsize . '" '; if($value instanceof \DateTime || $value instanceof \Mammut\Date\Date) { $value->setTimezone($system->getActiveTimezone()); $value = $value->format('d.m.Y H:i'); } if($value !== false) $html .= 'value="' . self::escapeString((string) $value) . '" '; if($this->isRequired()) { $html .= ' onblur="validate(\'' . self::escapeString($id) . '\',\'^.+$\',\'' . $css . '\',\'' . $css . '_error\',true);" '; $js_import[] = 'jscript/form/validate.js'; $js_submit .= ''; } $html .= '/>'; return array('html' => $html,'js_import' => $js_import,'js_submit' => $js_submit); } }