Zend Framework

Wrong calculation for GMT offset in Zend_Date

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.7.4
  • Fix Version/s: 1.8.0
  • Component/s: Zend_Date
  • Labels:
    None

Description

I have found a bug in the getGmtOffset() method of Zend_Date.

I try to get the current (2009/02/15) GMT offset to New Zealand timezone using the following code:

$date = new Zend_Date();
$date->setTimezone('Pacific/Auckland');
$offset = $date->getGmtOffset();

The offset variable contains now -43200 seconds (or -12 hours).

Trying to get the offset using plain PHP:

date_default_timezone_set('Pacific/Auckland');
$localtime = localtime(time(), true);
$offset = mktime($localtime['tm_hour'], $localtime['tm_min'], $localtime['tm_sec'], $localtime['tm_mon'] + 1, $localtime['tm_mday'], $localtime['tm_year'] + 1900) - gmmktime($localtime['tm_hour'], $localtime['tm_min'], $localtime['tm_sec'], $localtime['tm_mon'] + 1, $localtime['tm_mday'], $localtime['tm_year'] + 1900);

The offset variable contains now 46800 seconds (or -13 hours). This version pays attention to the summer/wintertime while the getGmtOffset() method always calculates a fixed offset. I think Zend_Date's method should do the same.

Activity

Hide
Thomas Weidner added a comment -

Changed with r14117

Show
Thomas Weidner added a comment - Changed with r14117

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: