yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.9k forks source link

Incorrect Timezone get in Application? #11917

Closed YGugnin closed 8 years ago

YGugnin commented 8 years ago

\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!

cebe commented 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.

cebe commented 8 years ago

note that setTimeZone() and getTimeZone() on the application are just wrappers for date_default_timezone_get()/set().

cebe commented 8 years ago

also not having date.timezone set in PHP config is not recommended: http://php.net/manual/en/function.date-default-timezone-get.php

YGugnin commented 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.

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

cebe commented 8 years ago

it throws a warning: https://3v4l.org/DUqTa

YGugnin commented 8 years ago

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?

cebe commented 8 years ago

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.

YGugnin commented 8 years ago

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 ;)

YGugnin commented 8 years ago

Or... May be better throw exception instead set UTC time?

cebe commented 8 years ago

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.

YGugnin commented 8 years ago

Oh. sorry. Didn't see it

cebe commented 8 years ago

no problem, that happended 11700 issues before this one :-)

YGugnin commented 8 years ago

ahah. Thank you. Have a nice day