Skip to content

Commit

Permalink
Fix validator format.
Browse files Browse the repository at this point in the history
  • Loading branch information
nkovacs committed Jul 3, 2015
1 parent 9d067d5 commit 743a044
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion DateTimeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace nkovacs\datetimepicker;

use Yii;
use yii\validators\Validator;

/**
Expand All @@ -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();
}

/**
Expand Down

0 comments on commit 743a044

Please sign in to comment.