Piwik timezones, date() and UTC = PROBLEM!


It seems piwik is resetting the default timezone in php with every call to the API.

In my code, after these 2 lines:
require_once PIWIK_INCLUDE_PATH . “/index.php”;
require_once PIWIK_INCLUDE_PATH . “/core/API/Request.php”;

My timezone stuff goes wrong. Whats worse is that it is corrupting phps date() function.

If I use date(‘I’) before those lines, it’s fine. I get a 1 (DST is being used). If I use it after I get 0. If I then use:

and then call date(‘I’) again it’s fine… until I call the API somewhere in the code.

Looking at the timestamps from time() they’re all correct BUT the times are being formed 1 hour behind London time (GMT +1 currently).

For example: it’s 17:49 now. If I get date(‘H:i:s’) before any piwik code it will give me the correct time. After those two require lines of code it will show 16:49 instead. The same applies all throughout the code.

I have checked my piwik settings, they are set to London in the root settings. The default timezone for new websites is London… yet the little i box shows UTC is an hour behind. It seems that piwik is sticking to UTC for everything.

So, to recap:

  1. date() doesn’t work correctly
  2. times are returned one hour behind.

Are you using Piwik in the PHP include mode? therefore it is true that Piwik will change all timezone to UTC. After the Piwik code, please put back the function call to set the timezone to London etc.

Hi Matt,

So does this mean that any output I get from the API will also be in UTC time too?

No it will be in the timezone specified for the website. But all php processing must be reset with:
@date_default_timezone_set( $TIMEZONE);