Skip to content

Commit

Permalink
Now supports php: format in time, date and dateTime
Browse files Browse the repository at this point in the history
  • Loading branch information
omnilight committed Sep 22, 2015
1 parent 03540c2 commit 1325155
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions DateTimeBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use yii\base\InvalidParamException;
use yii\db\BaseActiveRecord;
use yii\helpers\ArrayHelper;
use yii\helpers\FormatConverter;
use yii\i18n\Formatter;
use yii\validators\DateValidator;

Expand Down Expand Up @@ -143,11 +144,23 @@ public static function normalizeIcuFormat($format, $formatter)
if (is_string($format)) {
switch ($format) {
case 'date':
return ['date', $formatter->dateFormat];
$format = $formatter->dateFormat;
if (strncmp($format, 'php:', 4) === 0) {
$format = FormatConverter::convertDatePhpToIcu(substr($format, 4));
}
return ['date', $format];
case 'time':
return ['time', $formatter->timeFormat];
$format = $formatter->timeFormat;
if (strncmp($format, 'php:', 4) === 0) {
$format = FormatConverter::convertDatePhpToIcu(substr($format, 4));
}
return ['time', $format];
case 'datetime':
return ['datetime', $formatter->datetimeFormat];
$format = $formatter->datetimeFormat;
if (strncmp($format, 'php:', 4) === 0) {
$format = FormatConverter::convertDatePhpToIcu(substr($format, 4));
}
return ['datetime', $format];
default:
throw new InvalidParamException('$format has incorrect value');
}
Expand Down

0 comments on commit 1325155

Please sign in to comment.