Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datetime placeholder formatting not working as expected #5313

Closed
mg-code opened this issue Oct 2, 2014 · 2 comments
Closed

Datetime placeholder formatting not working as expected #5313

mg-code opened this issue Oct 2, 2014 · 2 comments
Assignees

Comments

@mg-code
Copy link
Contributor

mg-code commented Oct 2, 2014

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

@samdark samdark added this to the 2.0 GA milestone Oct 2, 2014
@samdark samdark added the status:to be verified Needs to be reproduced and validated. label Oct 2, 2014
@qiangxue qiangxue modified the milestones: 2.0 GA, 2.0.1 Oct 2, 2014
@cebe
Copy link
Member

cebe commented Oct 3, 2014

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 cebe added type:bug Bug and removed status:to be verified Needs to be reproduced and validated. labels Oct 3, 2014
@cebe cebe removed this from the 2.0.1 milestone Oct 16, 2014
@rugabarbo
Copy link
Member

@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.

@cebe cebe added this to the 2.0.17 milestone Apr 6, 2018
@samdark samdark closed this as completed Mar 20, 2019
@samdark samdark removed this from the 2.0.17 milestone Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants