DateTimePicker: implement getFormat()

refs #10847
This commit is contained in:
Alexander A. Klimov 2016-04-18 17:19:57 +02:00
parent 61a04e7ba1
commit 242cdab754
1 changed files with 11 additions and 1 deletions

View File

@ -112,6 +112,16 @@ class DateTimePicker extends FormElement
return $this->max; return $this->max;
} }
/**
* Get the expected date and time format of any user input
*
* @return string
*/
public function getFormat()
{
return $this->local ? 'Y-m-d\TH:i:s' : DateTime::RFC3339;
}
/** /**
* Is the date and time valid? * Is the date and time valid?
* *
@ -127,7 +137,7 @@ class DateTimePicker extends FormElement
} }
if (! $value instanceof DateTime) { if (! $value instanceof DateTime) {
$format = $this->local === true ? 'Y-m-d\TH:i:s' : DateTime::RFC3339; $format = $this->getFormat();
$dateTime = DateTime::createFromFormat($format, $value); $dateTime = DateTime::createFromFormat($format, $value);
if ($dateTime === false) { if ($dateTime === false) {
$dateTime = DateTime::createFromFormat(substr($format, 0, strrpos($format, ':')), $value); $dateTime = DateTime::createFromFormat(substr($format, 0, strrpos($format, ':')), $value);