I found bug with date&time formatting.
I set timezone to UTC (php.ini, yii config) and locale to en_US in my application.
When I use time placeholder in translations I always get wrong result. But when I use formatter class I get what I expected.
I debugged Yii code and found that translations is using MessageFormatter class, but Formatter->asTime is using IntlDateFormatter.
And looks like MessageFormatter class does not takes in account timezone.
Code:
var_dump(date("g:i A"));
var_dump(\Yii::$app->formatter->asTime(time(), 'short'));
var_dump(\Yii::t('time', '{0, time, short}', time()));
Result:
string '3:17 PM' (length=7) string '3:17 PM' (length=7) string '6:17 PM' (length=7)
I know it's not a Yii bug, but maybe this bug can be resolved on framework level.
Versions:
PHP: 5.4.16
ICU: 49.1.2
Issue related to PHP 5.2:
https://bugs.php.net/bug.php?id=58756
related to #4960 do not have an idea for a solution right now. Afaik the intl MessageFormatter has no option to configure the builtin number and date formatters.
@cebe @samdark
It seems that this is no longer relevant. Code:
echo PHP_VERSION . "\n";
echo INTL_ICU_DATA_VERSION . "\n";
echo INTL_ICU_VERSION . "\n";
date_default_timezone_set('America/Denver');
echo date("g:i A") . "\n";
echo \Yii::$app->i18n->format('{0, time, short}', time(), 'en_US') . "\n";
date_default_timezone_set('Europe/Moscow');
echo date("g:i A") . "\n";
echo \Yii::$app->i18n->format('{0, time, short}', time(), 'en_US') . "\n";
Result:
7.1.15-1+ubuntu16.04.1+deb.sury.org+2
55.1
55.1
7:16 AM
7:16 AM
4:16 PM
4:16 PM
The intl MessageFormatter still has no option to configure timezone: http://bugs.icu-project.org/trac/ticket/9330
But as you can see from my example it uses default_timezone.
Most helpful comment
@cebe @samdark
It seems that this is no longer relevant. Code:
Result:
The intl MessageFormatter still has no option to configure timezone: http://bugs.icu-project.org/trac/ticket/9330
But as you can see from my example it uses default_timezone.