diff --git a/README.md b/README.md index 7dabee3..654e0d4 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,10 @@ This package is a part of the Zend Framework 1. Each component was separated and **Autoloading!** Explicit `require_once` calls in the source code has been commented out to rely on composer autoloading, this reduces the number of included files to a minimum. **Migration!** Zend Framework 2 has been around for a while now, and migrating all your projects takes a lot of time. Using these packages makes it easier to migrate each component separately. Also, some packages doesn't exist in zf2 (such as the zend-search-lucene), now you can continue using that package without requiring the entire framework. + +## Changes after official 1.12.20 release + +- Zend_Date::setTime fix for DST change zendframework/zf1#682 ## How to use diff --git a/library/Zend/Date.php b/library/Zend/Date.php index 1d085a3..00a4402 100644 --- a/library/Zend/Date.php +++ b/library/Zend/Date.php @@ -2845,6 +2845,13 @@ private function _time($calc, $time, $format, $locale) * For example: dd.MMMM.yyTHH:mm' and 'ss sec'-> 10.May.07T25:11 and 44 sec => 1h11min44sec + 1 day * Returned is the new date object and the existing date is left as it was before * + * ADDED: Call the function twice to work around the DST bug + * http://zendframework.com/issues/browse/ZF-10584 + * https://github.com/zendframework/zf1/issues/682 + * http://stackoverflow.com/questions/7181702/work-around-for-zend-date-dst-bug + * http://stackoverflow.com/questions/8593660/zend-date-dst-bug-test-whether-a-date-is-a-time-change-date + * TODO: remove this once the bug is fixed + * * @param string|integer|array|Zend_Date $time Time to set * @param string $format OPTIONAL Timeformat for parsing input * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input @@ -2853,7 +2860,35 @@ private function _time($calc, $time, $format, $locale) */ public function setTime($time, $format = null, $locale = null) { - return $this->_time('set', $time, $format, $locale); + //return $this->_time('set', $time, $format, $locale); + + // start time zone juggling so that localtime() returns the correct results + $tzOrig = date_default_timezone_get(); + date_default_timezone_set($this->getTimezone()); + + // capture orignal info + $timeInfoOrg = localtime($this->getTimestamp(), true); + + // set the time + $ret = $this->_time('set', $time, $format, $locale); + + // if the dst has changed, perform workaround + $timeInfoNew = localtime($this->getTimestamp(), true); + if ((0 < $timeInfoOrg['tm_isdst']) != (0 < $timeInfoNew['tm_isdst'])) { + // set the time again + $ret = $this->_time('set', $time, $format, $locale); + // if the day changed, set it back + if ($timeInfoOrg['tm_yday'] != $timeInfoNew['tm_yday']) { + // localtime() year date is zero indexed, add one + $this->setDayOfYear($timeInfoOrg['tm_yday'] + 1); + } + } + + // end time zone juggling + date_default_timezone_set($tzOrig); + + // fluent + return $ret; }