ZF-11230: DST problems with Zend_Date::set() with Zend_Date::TIMES

Description

Use-case: today is 2011-03-27 and DST change has been applied at night. Timezone - Europe/Kiev


$from = new Zend_Date();
$from->set('00:00:00', Zend_Date::TIMES);

expected result: 2011-03-27 00:00:00

actual result: 2011-03-26T23:00:00+02:00

Comments

Proposed patch:

Zend_Date::_calculate, around line 2262 (case self::TIMES)


return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true),
                             $this->mktime($hour,           $minute,           $second,           $month, $day, $year, true), false);

change last parameter from false to $parsed['hour'], so _assign method will correct DST offset


return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true),
                             $this->mktime($hour,           $minute,           $second,           $month, $day, $year, true), $parsed['hour']);

Please give a complete date output for reproduction from the created and the changed date. Complete outputs can be created by $date->getIso() as described in the manual and the FAQ.

The patch is not accepted as it breaks existing tests.


$from = new Zend_Date();
print $from->getIso();

outputs

 


and

$from->set('00:00:00', Zend_Date::TIMES);
print $from->getIso();
outputs

2011-03-26T23:00:00+02:00 ````

Could you please specify, what test was broken? I've just run it with new test, result is OK:

{quote} Zend Framework Zend Framework - Zend Zend_DateTest .......................................................... ........................I.............................

Zend Framework - Zend_Date_Date Zend_Date_DateObjectTest ...................

Time: 48 seconds, Memory: 276.50Mb

There was 1 incomplete test:

1) Zend_DateTest::testTimesync NTP timeserver not available.

D:\Denwer\home\zf\www\tests\Zend\DateTest.php:4973 OK, but incomplete or skipped tests! Tests: 131, Assertions: 1868, Incomplete: 1. {quote}

Unfortunately, I can't attach a patch as a file, so I attach it inline :)


Index: library/Zend/Date.php
===================================================================
--- library/Zend/Date.php   (revision 23872)
+++ library/Zend/Date.php   (working copy)
@@ -2260,7 +2260,7 @@
                     }
                     $parsed = Zend_Locale_Format::getTime($date, array('locale' => $locale, 'format_type' => 'iso', 'fix_date' => true));
                     return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true),
-                                                 $this->mktime($hour,           $minute,           $second,           $month, $day, $year, true), false);
+                                                 $this->mktime($hour,           $minute,           $second,           $month, $day, $year, true), $parsed['hour']);
                 } catch (Zend_Locale_Exception $e) {
                     require_once 'Zend/Date/Exception.php';
                     throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
Index: tests/Zend/DateTest.php
===================================================================
--- tests/Zend/DateTest.php (revision 23872)
+++ tests/Zend/DateTest.php (working copy)
@@ -5669,6 +5669,17 @@
         $date = new Zend_Date(array('year' => 2008, 'month' => 10, 'day' => 12));
         $this->assertEquals('2008年10月12日', $date->get(Zend_Date::DATE_LONG, 'zh'));
     }
+   
+    /**
+     * @ZF-11230
+     */
+    public function testSetDateWithTimesPartOnDSTChange()
+    {
+        date_default_timezone_set('Europe/Kiev');
+        $date  = new Zend_Date(strtotime('2011-03-27T23:04:32+03:00'));
+        $date->set('00:00:00', Zend_Date::TIMES);
+        $this->assertEquals('2011-03-27T00:00:00+02:00', $date->getIso());
+    }
 }
 
 class Zend_Date_TestHelper extends Zend_Date