Closed YGugnin closed 8 years ago
date_default_timezone_get() will get the value from date.timezone
. if that does not exist, it will throw an error, so that does not make sense.
note that setTimeZone()
and getTimeZone()
on the application are just wrappers for date_default_timezone_get()/set().
also not having date.timezone set in PHP config is not recommended: http://php.net/manual/en/function.date-default-timezone-get.php
date_default_timezone_get() will get the value from date.timezone. if that does not exist, it will throw an error, so that does not make sense.
Ubuntu 15.10 Apache/2.4.12 PHP 5.6.11 No date.timezone into php ini file....
ini_get("date.timezone") is string(0) "" date_default_timezone_get() is "Europe/Helsinki" ...
also php have default ini file after install....
it throws a warning: https://3v4l.org/DUqTa
Ok. Like you want. Of сourse I already fixed it. But before I had different mysql and php time. It was because framework sets UTC time by default. It looks like error. isn't it?
If Yii would not set the timezone itself you would see an exception in this case so everything is correct.
PHP documentation is very clear about the fact that you should not leave date.timezone
empty.
Yes. But empty date.timezone this is just warning, but "incorrect" timezone perhaps will throw critical error. I love Yii and just want to make it better ;)
Or... May be better throw exception instead set UTC time?
this behavior was added in https://github.com/yiisoft/yii2/commit/b8ad3567e44f818d7b45f20bf1ebdfa274f90dfb see #209 and #210 for the discussion about it. Imo the current solution is the best one.
Oh. sorry. Didn't see it
no problem, that happended 11700 issues before this one :-)
ahah. Thank you. Have a nice day
\vendor\yiisoft\yii2\base\Application.php
Lines 244 - 249:
if (isset($config['timeZone'])) { $this->setTimeZone($config['timeZone']); unset($config['timeZone']); } elseif (!ini_get('date.timezone')) { $this->setTimeZone('UTC');
}
I have no date.timezone into my php ini file. So it's set timeZone to UTC. But my current timezone is Europe/Helsinki.
Sure, I can set timeZone to Europe/Helsinki, but I think this is incorrect. You should get timezone from date_default_timezone_get before set UTC.
Thank you!