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
Formatter ignore timeZone #5328
Comments
The formatter uses UTC as the input timezone when you input a value that has no timezone specified explicitly. You should always store date/time values in UTC and convert them to the right timezone when displaying. If you store them in another timezone you have to specify the timezone explicitly: // assuming Yii::$app->timeZone = 'Europe/Berlin';
\Yii::$app->formatter->asTime('2014-08-10 12:41:00'); // 14:41:00
\Yii::$app->formatter->asTime('2014-08-10 14:41:00 CEST'); // 14:41:00 See also 6267b9e |
thnk u! i'm understood. |
There is still a problem with this when you use DatePicker I give you an example: I don't know what is the best fix for this in overall. But in this specific case it seems that using same timezone in initial conversion would fix it. But where should this be handled? In the DatePicker widget? In the formatter? |
This is a general problem with dates because they are not really timezone related. Can you please open a new issue for this? will try to find a solution for this. maybe for date values that do not include time, we should normalize them differently than full time values. |
this timezone changed the rules recently, so your server may not be up to date. See http://www.yiiframework.com/doc-2.0/guide-tutorial-i18n.html#setup-environment for how to update. Also note that a UNIX timestamp is, per definition, always in UTC, so |
updated docs: b056dff hope its more clear now. |
@cebe I think no one here has had problem understanding that timestamp is in UTC. The problem is that all the user input dates are treated as in UTC - although they should be treated as the same timeZone the application output is set at. Because user inputs dates/times in the same timezone he uses the app at. PS! Correct me if I'm wrong. I haven't tested it lately - maybe this is a non issue and has been fixed already. |
@Renkas my reply was to a comment that has been deleted, so I can not re-check if I maybe understood the problem wrong. For user input, it should not be formatted directly with Formatter but it should be converted by DateValidator first, so you get a value in UTC or whatever you have configured as defaultTimeZone. which you can then format using the formatter. |
ICU is not shipped with PHP, it depends on the libraries that are installed on your server.
|
i set timezone in my.conf
in my php.ini:
in application config:
then i use this example
Formatter added +4 hours if use date as string, but all ok if use timestamp.
i think this problem in framework\i18n\Formatter method normalizeDatetimeValue
(https://github.com/yiisoft/yii2/blob/master/framework/i18n/Formatter.php#L565-L592)
there set DateTimeZone('UTC') and string time converted in this timezone , but i think need use $this->timeZone.
The text was updated successfully, but these errors were encountered: