From: Matthias Schmidt Date: Sun, 13 Jan 2019 09:05:29 +0000 (+0100) Subject: Fix internal value format after setting value of date form field X-Git-Tag: 5.2.0_Alpha_1~365^2~6 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b1a577cf0dff4766984334bd07a3e8c88ca4144f;p=GitHub%2FWoltLab%2FWCF.git Fix internal value format after setting value of date form field See #2509 --- 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; + } }