diff --git a/src/Inputs/DateTimeInput.php b/src/Inputs/DateTimeInput.php index 7522b5e..37dc1bf 100644 --- a/src/Inputs/DateTimeInput.php +++ b/src/Inputs/DateTimeInput.php @@ -13,6 +13,7 @@ use Czubehead\BootstrapForms\Enums\DateTimeFormat; use DateTime; +use Nette\InvalidArgumentException; use Nette\NotSupportedException; @@ -59,6 +60,25 @@ public function getValue() return $value; } + /** + * @param DateTime|null $value + * @return static + */ + public function setValue($value) + { + if ($value instanceof DateTime) { + parent::setValue($value->format($this->format)); + + return $this; + } + elseif ($value === NULL) { + parent::setValue(NULL); + + return $this; + } + throw new InvalidArgumentException('Value must be either DateTime or NULL'); + } + public function validate() { parent::validate();