From 242cdab7544a624b7a41a0e7ce1d75e5a55c8183 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 18 Apr 2016 17:19:57 +0200 Subject: [PATCH] DateTimePicker: implement getFormat() refs #10847 --- library/Icinga/Web/Form/Element/DateTimePicker.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Web/Form/Element/DateTimePicker.php b/library/Icinga/Web/Form/Element/DateTimePicker.php index 2173c6c8a..f48742ea6 100644 --- a/library/Icinga/Web/Form/Element/DateTimePicker.php +++ b/library/Icinga/Web/Form/Element/DateTimePicker.php @@ -112,6 +112,16 @@ class DateTimePicker extends FormElement 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? * @@ -127,7 +137,7 @@ class DateTimePicker extends FormElement } if (! $value instanceof DateTime) { - $format = $this->local === true ? 'Y-m-d\TH:i:s' : DateTime::RFC3339; + $format = $this->getFormat(); $dateTime = DateTime::createFromFormat($format, $value); if ($dateTime === false) { $dateTime = DateTime::createFromFormat(substr($format, 0, strrpos($format, ':')), $value);