From b1a577cf0dff4766984334bd07a3e8c88ca4144f Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 13 Jan 2019 10:05:29 +0100 Subject: [PATCH] Fix internal value format after setting value of date form field See #2509 --- .../builder/field/DateFormField.class.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/wcfsetup/install/files/lib/system/form/builder/field/DateFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/DateFormField.class.php index e81260797a..c8e599a11c 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/DateFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/DateFormField.class.php @@ -154,4 +154,25 @@ class DateFormField extends AbstractFormField { } } } + + /** + * @inheritDoc + */ + public function value($value) { + parent::value($value); + + $dateTime = \DateTime::createFromFormat($this->getSaveValueFormat(), $this->getValue()); + if ($dateTime === false) { + throw new \InvalidArgumentException("Given value does not match format `{$this->getSaveValueFormat()}`."); + } + + if ($this->supportsTime()) { + parent::value($dateTime->format('Y-m-d\TH:i:sP')); + } + else { + parent::value($dateTime->format('Y-m-d')); + } + + return $this; + } } -- 2.20.1