From 1325155fd8dd77b56f3448e8c7ace2be0de61303 Mon Sep 17 00:00:00 2001 From: Pavel Date: Tue, 22 Sep 2015 11:33:53 +0300 Subject: [PATCH] Now supports php: format in time, date and dateTime --- DateTimeBehavior.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/DateTimeBehavior.php b/DateTimeBehavior.php index 33cdfe2..bcbc029 100644 --- a/DateTimeBehavior.php +++ b/DateTimeBehavior.php @@ -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; @@ -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'); }