From 743a044d049bdac77cbe414f949087a294501603 Mon Sep 17 00:00:00 2001 From: Nikola Kovacs Date: Fri, 3 Jul 2015 14:23:47 +0200 Subject: [PATCH] Fix validator format. --- DateTimeValidator.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/DateTimeValidator.php b/DateTimeValidator.php index 429c23f..809c76d 100644 --- a/DateTimeValidator.php +++ b/DateTimeValidator.php @@ -2,6 +2,7 @@ namespace nkovacs\datetimepicker; +use Yii; use yii\validators\Validator; /** @@ -21,10 +22,25 @@ class DateTimeValidator extends \yii\validators\DateValidator */ public function init() { - parent::init(); + if ($this->format === null) { + switch ($this->type) { + case 'date': + $this->format = Yii::$app->formatter->dateFormat; + break; + case 'time': + $this->format = Yii::$app->formatter->timeFormat; + break; + case 'datetime': + $this->format = Yii::$app->formatter->datetimeFormat; + break; + } + } + // if $this->format is a short format, // convert it to a pattern, so that DateValidator will respect $this->type. $this->format = FormatConverter::convertIcuShortFormatToPattern($this->format, $this->type, $this->locale); + + parent::init(); } /**