Fix internal value format after setting value of date form field
authorMatthias Schmidt <gravatronics@live.com>
Sun, 13 Jan 2019 09:05:29 +0000 (10:05 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 13 Jan 2019 09:05:29 +0000 (10:05 +0100)
See #2509

wcfsetup/install/files/lib/system/form/builder/field/DateFormField.class.php

index e81260797aef13e1f18ba88282205924e03e6d19..c8e599a11c467b9215c964afdf24e0d394d41c27 100644 (file)
@@ -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;
+       }
 }