I have a script that daily do bulk import of log files to a "my_logs_db.logs" Table that will be queried by CakePHP3
app.
In the "logs" table I have a datetime field named 'date_time'
. Imported Date for 'date_time'
field refers to system timezone that is set to 'Europe/Paris'
and not 'UTC'
What I want is to display date_time field with the application timezone, for example : 'Indian/Reunion' (UTC+4).
So I tried this :
I set timezone to SYSTEM for on the data source config/app.php
. With this value MySQL should work with system time that is set to Europe/Paris
:
'my_logs_db' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
//'port' => 'non_standard_port_number',
'username' => 'user',
'password' => '*********',
'database' => 'my_logs_db',
'encoding' => 'utf8',
'timezone' => 'SYSTEM',
'flags' => [],
'cacheMetadata' => true,
'log' => false,
'quoteIdentifiers' => false,
//'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
'url' => env('DATABASE_URL', null),
],
Somewhere in my Controller I set the timezone to use for display :
date_default_timezone_set('Indian/Reunion')
Somewhere in my Controller the SQL query is :
$logs = $this->Logs->find();
$logs->select([
'id',
'date_time',
'client_ip',
'domain',
]);
When I debug date_time, I get this :
object(Cake\I18n\FrozenTime) {
'time' => '2019-02-28T01:56:58+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
}
And the displayed date is 2019-02-28 05:56:58 (UTC+4).
This is not the right time to display.
The date I want to display is 2019-02-28 04:56:58 (Europe/Paris+3)
So the output I want if I debug date_time must be like :
object(Cake\I18n\FrozenTime) {
'time' => '2019-02-28T01:56:58+00:00',
'timezone' => 'Europe/Paris',
'fixedNowTime' => false
}
The datetime I want should be unchanged and the timezone should be set to 'Europe/Paris'
For "FrozenTime" how to set timezone to 'Europe/Paris' and not 'UTC' ? Or do I have to add something in my SQL query ?
Note that I don't want to change system timezone to UTC as work arround.