Skip to content
This repository has been archived by the owner on Aug 12, 2019. It is now read-only.

Commit

Permalink
Merge pull request #55 from premekkoch/master
Browse files Browse the repository at this point in the history
Support for DateTimeInterface types
  • Loading branch information
hrach authored Oct 31, 2017
2 parents 6cc2aea + 656ce99 commit 895eee8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Controls/DateTimePickerPrototype.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace Nextras\Forms\Controls;

use Closure;
use DateTime;
use DateTimeInterface;
use Nette;
use Nette\Forms\Controls\TextBase;
use Nette\Forms\Form;
Expand Down Expand Up @@ -48,14 +48,14 @@ public function getControl()
$control->addClass($this->htmlType);

list($min, $max) = $this->extractRangeRule($this->getRules());
if ($min instanceof DateTime) {
if ($min instanceof DateTimeInterface) {
$control->min = $min->format($this->htmlFormat);
}
if ($max instanceof DateTime) {
if ($max instanceof DateTimeInterface) {
$control->max = $max->format($this->htmlFormat);
}
$value = $this->getValue();
if ($value instanceof DateTime) {
if ($value instanceof DateTimeInterface) {
$control->value = $value->format($this->htmlFormat);
}

Expand All @@ -65,7 +65,7 @@ public function getControl()

public function setValue($value)
{
return parent::setValue($value instanceof \DateTimeInterface ? $value->format($this->htmlFormat) : $value);
return parent::setValue($value instanceof DateTimeInterface ? $value->format($this->htmlFormat) : $value);
}


Expand All @@ -74,7 +74,7 @@ public function setValue($value)
*/
public function getValue()
{
if ($this->value instanceof DateTime) {
if ($this->value instanceof DateTimeInterface) {
// clone
return Nette\Utils\DateTime::from($this->value);

Expand All @@ -91,7 +91,7 @@ public function getValue()

foreach ($parsers as $parser) {
$value = $parser($this->value);
if ($value instanceof DateTime) {
if ($value instanceof DateTimeInterface) {
return $value;
}
}
Expand Down

0 comments on commit 895eee8

Please sign in to comment.