Edit report at https://bugs.php.net/bug.php?id=55253&edit=1
ID: 55253 Comment by: dani...@php.net Reported by: danielc at analysisandsolutions dot com Summary: DateTime::add() and sub() result -1 hour on objects with time zone type 2 Status: Open Type: Bug Package: Date/time related Operating System: Ubuntu 10.04 PHP Version: 5.4SVN-2011-07-20 (SVN) Block user comment: N Private report: N New Comment: This is probably related to https://bugs.php.net/bug.php?id=60236 Previous Comments: ------------------------------------------------------------------------ [2011-07-20 14:24:08] dani...@php.net Automatic comment from SVN on behalf of danielc Revision: http://svn.php.net/viewvc/?view=revision&revision=313484 Log: Rename and enhance test for bug 55253 now that bugs web is up. ------------------------------------------------------------------------ [2011-07-20 14:18:36] danielc at analysisandsolutions dot com Description: ------------ Calling add() or sub() on DateTime objects using a type 2 time zone results in the answer being behind by one hour. Test script has been added to SVN. Test script: --------------- date_default_timezone_set('America/New_York'); $interval = new DateInterval('PT2H1M'); $date3 = new DateTime('2010-10-04 02:18:48'); $date2 = new DateTime('2010-10-04 02:18:48 EDT'); echo 'Zone Type 3: ' . $date3->format('Y-m-d H:i:s T') . "\n"; echo 'Zone Type 2: ' . $date2->format('Y-m-d H:i:s T') . "\n"; echo $interval->format('Add %h hours %i minutes') . "\n"; $date3->add($interval); $date2->add($interval); echo 'Zone Type 3: ' . $date3->format('Y-m-d H:i:s T') . "\n"; echo 'Zone Type 2: ' . $date2->format('Y-m-d H:i:s T') . "\n"; // Try subtracting from expected result. $date3 = new DateTime('2010-10-04 04:19:48'); $date2 = new DateTime('2010-10-04 04:19:48 EDT'); echo $interval->format('Subtract %h hours %i minutes from expected') . "\n"; $date3->sub($interval); $date2->sub($interval); echo 'Zone Type 3: ' . $date3->format('Y-m-d H:i:s T') . "\n"; echo 'Zone Type 2: ' . $date2->format('Y-m-d H:i:s T') . "\n"; Expected result: ---------------- Zone Type 3: 2010-10-04 02:18:48 EDT Zone Type 2: 2010-10-04 02:18:48 EDT Add 2 hours 1 minutes Zone Type 3: 2010-10-04 04:19:48 EDT Zone Type 2: 2010-10-04 04:19:48 EDT Subtract 2 hours 1 minutes from expected Zone Type 3: 2010-10-04 02:18:48 EDT Zone Type 2: 2010-10-04 02:18:48 EDT Actual result: -------------- Zone Type 3: 2010-10-04 02:18:48 EDT Zone Type 2: 2010-10-04 02:18:48 EDT Add 2 hours 1 minutes Zone Type 3: 2010-10-04 04:19:48 EDT Zone Type 2: 2010-10-04 03:19:48 EDT Subtract 2 hours 1 minutes from expected Zone Type 3: 2010-10-04 02:18:48 EDT Zone Type 2: 2010-10-04 01:18:48 EDT ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55253&edit=1