It doesn't work at all because of function names are confused. It should be date('Z') instead of time('Z') in lines 1093, 1095. Time() has no parameters and returns current Unix timestamp. Date('Z') returns current timezone offset in seconds.

handlers.inc:1090-1097

   $offset = $set_offset !== NULL ? $set_offset : views_get_timezone();
  if (isset($offset) && !is_numeric($offset)) {
    $tz = date_default_timezone_get();
    $current = time('Z');
    date_default_timezone_set($offset);
    $offset_seconds = $current - time('Z');
    date_default_timezone_set($tz);
  }

But is it correct re-set default timezone (twice per query) to get the offset value? Why not use DateTimeZone and DateTime objects?

And if configurable timezones are disabled, views_get_timezone() returns default timezone and $offset_seconds will be 0 instead of default timezone offset. Why $offset_seconds is calculated as a difference between default and user's timezone offsets? The value stored in the database is the UTC timestamp, isn't it? In this case we should add either user's (if configured) or default timezone offset. Something like this:

  $offset = $set_offset !== NULL ? $set_offset : views_get_timezone();
  if (isset($offset) && !is_numeric($offset)) {
    $dtz = new DateTimeZone($offset);
    $dt = new DateTime("now", $dtz);
    $offset_seconds = $dtz->getOffset($dt);
  }
CommentFileSizeAuthor
#1 views_timezone.patch628 bytesQajrat

Comments

Qajrat’s picture

StatusFileSize
new628 bytes
dawehner’s picture

Status: Active » Needs review

Update status.

dawehner’s picture

Status: Needs review » Fixed

Okay read some documentation on php.net and this seems to be the way to use this php 5.2 stuff.

Also tryed out the basic functionality so commited.

Thanks for the patch!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.