Post by ecoleman » Thu Apr 18, 2019 4:05 pm

So, I've come across a very strange problem since upgrading to OC 2.3.0.2.
The server and the database timezones are set correctly UK which is currently BST (GMT+1).
When an order is created the SQL query uses the NOW() function to insert the date date_added column which is correct.

I noticed however, that the customers online was out by an hour so I took a look at the model and this was using date("Y-m-d H:i:s") to insert the date which was an hour behind. At first I thought the server timezone was incorrect and took it up with the ISP but they confirmed that the server timezone was correctly set and if I create a small php file with echo (date"Y-m-d H:i:s") outside of Opencart then the correct date and time is displayed.

If I output the date function to opencarts log file then the time is an hour behind.

I also have an abandoned cart extension which looks at the time of the cart and if more than half an hour it sends the customer an email, this is also not working correctly as it also uses the PHP date function to calculate this. It's running an hour behind.

It seems that Opencart is setting a timezone somewhere. Anybody know about this and where it may be set so that it can be fixed?

Cheers
Elliott

Colour Code you orders by Order Status


Active Member

Posts

Joined
Tue Dec 06, 2011 3:34 am

Post by ecoleman » Thu Apr 18, 2019 4:31 pm

Further to above, I have found a timezone setting in startup.php however this doesn't seem to do anything.

My ini file is set to Europe/London and even if I comment out the ini_get and force the timezone, it doesn't change.

//if (!ini_get('date.timezone')) {
date_default_timezone_set('Europe/London');
//}

Colour Code you orders by Order Status


Active Member

Posts

Joined
Tue Dec 06, 2011 3:34 am

Post by ecoleman » Thu Apr 18, 2019 5:07 pm

I've done another test and it does point to opencart setting the timezone to UTC somewhere, but not in the startup.php file as I've commented that out and also changed UTC to Europe/London

If I create a small PHP file and run this completely standalone from opencart this is the output

Code: Select all

This is the Timezone from ini file using ini_get('date.timezone') : Europe/London
This is the value from date_default_timezone_get() : Europe/London
this is the time using date('Y-m-d H:i:s') : 2019-04-18 10:00:27
Now we set a default timezone using date_default_timezone_set('Europe/London')
this is the time using date('Y-m-d H:i:s') : 2019-04-18 10:00:27
Now the same code but called from the header controller and output to the log file

Code: Select all

2019-04-18 8:53:59 - ControllerCommonHeader/index - This is the Timezone from ini file using ini_get('date.timezone') : Europe/London
2019-04-18 8:53:59 - ControllerCommonHeader/index - This is the value from date_default_timezone_get() : UTC
2019-04-18 8:53:59 - ControllerCommonHeader/index - this is the time using date('Y-m-d H:i:s') : 2019-04-18 08:53:59
2019-04-18 8:53:59 - ControllerCommonHeader/index - Now we set a default timezone using date_default_timezone_set('Europe/London')
2019-04-18 9:53:59 - ControllerCommonHeader/index - this is the time using date('Y-m-d H:i:s') : 2019-04-18 09:53:59
See how the ini is correctly reporting Europe/London in the first line but date_default_timezone is set to UTC. Once I change that the time reports correctly.

However, even if I leave this line of code to change the timezone, if date is called anywhere else it's reverted back to UTC.

Colour Code you orders by Order Status


Active Member

Posts

Joined
Tue Dec 06, 2011 3:34 am
Who is online

Users browsing this forum: Alexa [Bot] and 109 guests