@adaqus opened this Issue on February 10th 2016


Let's say we want to create new Date instance with custom timezone:

$date = Date::factory('2016-01-26', 'America/New_York');

In this factory it is assumed that input date is always in UTC, so I would expect following behavior:

  • $date->getDatetime() should return value from custom timezone '2016-01-25 19:00:00' and it works this way,
  • $date->getDateStartUTC() should return original UTC value '2016-01-26 00:00:00', it returns '2016-01-25 00:00:00' instead.


Let's create new Range period instance:

$period = new Range('day', '2016-01-26,2016-01-27', 'America/New_York');

This is how this period behaves:

  • $period->getDateStart()->getDatetime() should return '2016-01-25 19:00:00', it returns '2016-01-26 00:00:00',
  • $period->getDateStart()->getDateStartUTC() should return '2016-01-26 00:00:00' and it does.
@tsteur commented on February 10th 2016 Owner

That looks like a bug indeed and it could cause problems as it seems to be used around Archiving etc. In this line https://github.com/piwik/piwik/blob/2.16.0/core/Date.php#L190 it applies the timezone so it doesn't return the start of the day in UTC but in the given timezone.

The description of the method says:

Returns the start of the day of the current timestamp in UTC.

but it looks like it definitely doesn't. However, I wonder, if maybe only the name of the method and the description is wrong so far and the behaviour is maybe expected? Really surprised that the timezone is applied there when it specifically says UTC. @mattab any ideas?

We should make Period\Factory public API and remove API from __constructor maybe to force creation of Periods via the factory? Not sure!

Powered by GitHub Issue Mirror