Details
Description
This problem seems to occure only when the timezone is "UTC" ...
The code that I think is problematic is in Zend/Date.php, about the 1290th row ...
// dst-correction if 'fix_dst' = true and dst !== false if ((self::$_Options['fix_dst'] === true) and ($dst !== false)) { $hour = $this->get(Zend_Date::HOUR); if ($hour != $dst) { if (($dst == ($hour + 1)) or ($dst == ($hour - 23))) { $value += 3600; } else if (($dst == ($hour - 1)) or ($dst == ($hour + 23))) { $value -= 3600; } $this->setUnixTimestamp($value); } }
The problem occured when I tried this method of creating a date
// Set a default timezone... this has to be done within the bootstrap file or php.ini // We do this here just for having a complete example date_default_timezone_set('UTC'); $Y = 2007; $m = 1; $d = 1; $H = 20; $i = 45; $s = 37; $arr = array('year' => $Y, 'month' => $m, 'day' => $d, 'hour' => $H, 'minute' => $i, 'second' => $s); $date = new Zend_Date($arr); echo $date->toString('r');
The out put is "Mon, 01 Jan 2007 20:45:37 +0000" and it's OK
but if the $H variable is:
$H = 1; // the output is "Mon, 01 Jan 2007 00:45:37 +0000"
$H = 23; // the output is "Tue, 02 Jan 2007 00:45:37 +0000"
This does not happen if the timezone is different from "UTC" ... and as far as I know DST doesn'y apply to UTC/GMT
This thing fix the above problem
// dst-correction if 'fix_dst' = true and dst !== false $zone = @date_default_timezone_get(); if ((self::$_Options['fix_dst'] === true) and ($dst !== false) and ($zone != 'UTC')) {
but I'm not sure how this interact with the rest of the ZF code and i'm not sure that this is the most elegant way to fix the problem ... if it's a real problem anyway
... I hope this is not my mistake or misunderstanding of the way the fix_dst works
EDIT:
As I get deep into the code I found something that may be the problem ... The fix above probably in not the right way to fix it ...
So I followed the path of the arrat throw the functions in Zend_Date:
1. Line 160 the constructor
2. Line 201 $this->set()
3. Line 1154 function set(....)
4. Line 1156 return $result = $this->_calculate('set', $date, $part, $locale);
5. Line 1315 function _calculate ....
this is almost the end of the journey ...
Line 1338: $hour = $this->get(Zend_Date::HOUR_SHORT); //as I tested ... it's alway 0 ... because the $_unixTimestamp in the Date_Object is 0 ...
Line 1466: return $this->_assign($calc, $this->mktime($hours, $minutes, $seconds, $months, $days, $years, true),
$this->mktime($hour, $minute, $second, $month, $day, $year, true), $hour);
$hour is used as last argument in _assign ...
private function _assign($calc, $date, $comp = 0, $dst = false)
so $hour is $dst in _assign function ... and $dst is used in "dst_fix" ...
$dst is 0 ... and when $hour is 23 or 1 ... an hour is added or substracted ....
If you do not want to take DST in account you have to use
Zend_Date::setOptions(array('fix_dst' => false));See http://framework.zend.com/manual/en/zend.date.overview.html - DST and Date Math
for detailed information.
Zend_Date::setOptions(array('fix_dst' => false));