In ver 3.3.3 I set in bootstrap date_default_timezone_set(‘America/Chicago’);
But in config/app there is this line
'timezone' => 'UTC',
Exactly what is this line for, and do I leave it or change it to local timezone as well. Times are currently storing correctly.
And a side note I do not use and do not believe in timestamps. I use a date field or if needed a datetime field in the mysql database.
The 'timezone'
item in config/app.php
is included in the 'Datasources'
section, so that means that it’s related to the database time zone configured in the database server.
I set UTC as a time zone for everything: the system, the database server, etc. every time that I can. If my customer requires another time zone, then I configure it on the app.
Regarding date_default_timezone_set('America/Chicago');
there’s a recommendation in the comments of bootstrap.php
:
/*
* Set server timezone to UTC. You can change it to another timezone of your
* choice but using UTC makes time calculations / conversions easier.
*/
In the 2.x book, there’s some indication that seems to have disappeared in the 3.x book: https://book.cakephp.org/2.0/en/installation.html#fire-it-up recommending to uncomment the line in case of issues.
In my case, I almost always prefer timestamps rather than datetime fields, because timestamps include the timezone implicitly. So, since the moment that the app will be accessed from users from different time zones and you want them to see dates and times in their local timezone, this field type makes it pretty easy to do it than if the data were saved in datetime fields.
As a plus, in the case of a migration of the database to a system with another timezone, I would feel more confident using timestamps. Not to say possible issues when calculating differences between two moments with a sumer time change in between and needing a precision of 1 hour or less.
For all this reasons, I choose UTC & timestamp fields where posible. And I avoid headaches