-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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 formatting problem with Russian timezones #5128
Comments
Will look into this and see if we can provide a configuration setting for the tzdata to use. |
Thanks, @cebe. Also, I think that current implementation is not good for date formatting. Let's see at this example: $formatter = new \yii\i18n\Formatter;
$formatter->dateFormat = 'php:Y-m-d';
$formatter->timeZone = 'UTC';
echo $formatter->asDate('2014-02-01'); We will get |
Thats a general problem with dates, when I create something on 2014-02-01 somewhere on the world it is not the 2014-02-01 but the 2014-01-31 ;) hard to change that. You need to store complete timestamps and convert them to the correct timezone. When only storing the date it is hard to find a correct solution for that. |
What can you suggest to use when I need just change a date format of a string? For example, when user input is |
when you ensure you stay in the same timezone for both input and output it should be fine... needs to make some tests to make sure there is not a bug. |
When u are developing a website/application that has to do with timezones u need to save it as utc date and present it to the frontend with the right timezone. An usefull tool for this is to use the datetime object u can change the timezone of it to get the right representation for every timezone. |
Yes, I understand, that in multi-timezone applications I need to store datetime values in one general timezone. But my problem described in first message is not related to multi-timezone application: I just converted a date (changed format without changing the TZ) and got very strange results (because of ICU outdated TZ data). The second message was just an opinion about |
Multi-timezone support was not working correctly before. This is fixed by 6267b9e @RomeroMsk can you test again with the latest code? Regarding the outdated timezone db, can you check whether installing the pecl timezonedb as described in http://php.net/manual/en/timezones.php fixes your problem? |
@cebe, I can't test it now, because we've upgraded ICU TZ data to the newest one. |
Thanks, added the information to the guide. |
At first, method $DT = new \DateTime;
var_dump($DT->format('c')); //2015-12-17T17:05:02+03:00
var_dump(\Yii::$app->getFormatter()->asDatetime($DT)); //17 дек. 2015 г., 18:05:02 Assume, it's server software problem, but input value already contain TZ info, why not use it for cleanly behavior? At second, updating timezonedb so hard on some systems, e.g. CentOS 6.x (with all updates and enabled popular update repos) now contain old libicu (Version: 50.1.2 Release Date: 2012-12-17). Updating (http://habrahabr.ru/post/241447/) is not trivial and stable. I suggest, pass tz-argument for instantiate
I can create PR for it. |
@Yiivgeny please open a new issue, this one is really old. |
I've encountered very nasty situation with
IntlDateFormatter
which is used now insideFormatter
component. Just want to warn another developers (and maybe it could be included into docs).I'm using Russian timezones:
Europe/Moscow
, for example (GMT +4). And today I've noticed that formatting01.02.2014 00:00:00
value tophp:Y-m-d H:i:s
is giving2014-01-31 23:00:00
. After some investigation I've found the root of this problem: an outdated time zone DB inside ICU lib (which is used by Intl extension). ICU is not using system TZ data, but using its own TZ database files :-(Our server is using ICU 4.2 which contains a 2009j version of timezone database. But there was a timezone change in Russia in 2011. So to override the problem we need to use newer version of ICU (or TZ data inside ICU). Here is the last stable version of ICU: http://site.icu-project.org/download/53, but it uses only 2014b timezone database. ICU 54 (with 2014g) is in RC and not recommended for production now: http://site.icu-project.org/download/54. But on October, 2014 timezones will be changed again in Russia, so all developers must use newest TZ data (2014f or newer) inside ICU (not only in OS) to help their Russian users to not experience such issues.
Can anyone confirm this problem? Check your version of ICU (in
Configuration
tab of debugger toolbar, for example) and try to format the date before 2014-03-31 withEurope/Moscow
timezone like this:If you see
2014-01-31 23:00:00
, you have this issue too.The text was updated successfully, but these errors were encountered: