Bug #71833 [NEW]: DateTime - incorrect calculation for add()

From: Date: Tue, 15 Mar 2016 21:03:24 +0000
Subject: Bug #71833 [NEW]: DateTime - incorrect calculation for add()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199850@lists.php.net to get a copy of this message
From: troy_rudolph at bridge360 dot com Operating system: windows and linux PHP version: 5.6.19 Package: Date/time related Bug Type: Bug Bug description:DateTime - incorrect calculation for add() Description: ------------ Adding a year to a DateTime produces different results for different timezone. IMO, the test script below should produce two identical date/time strings. However, the actual results are an hour apart. Expected: 03/12/2016 12:00 am 03/12/2016 12:00 pm Actual: 03/12/2016 12:00 am 03/11/2016 11:00 pm Thank you! Test script: --------------- <?php $ct = new \DateTimeZone('America/Chicago'); $utc = new \DateTimeZone('UTC'); $oneYear = new \DateInterval('P1Y'); $date1 = \DateTime::createFromFormat('Y-m-d H:i:s', '2015-03-12 00:00:00', $ct); $date1->add($oneYear); echo "\n". $date1->format("m/d/Y h:i a"); $date2 = \DateTime::createFromFormat('Y-m-d H:i:s', '2015-03-12 00:00:00', $ct); $date2->setTimezone($utc); $date2->add($oneYear); $date2->setTimezone($ct); echo "\n". $date2->format("m/d/Y h:i a"); Expected result: ---------------- Expected: 03/12/2016 12:00 am 03/12/2016 12:00 pm Actual result: -------------- Actual: 03/12/2016 12:00 am 03/11/2016 11:00 pm -- Edit bug report at https://bugs.php.net/bug.php?id=71833&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71833&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71833&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71833&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=71833&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=71833&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=71833&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=71833&r=needscript Try newer version: https://bugs.php.net/fix.php?id=71833&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=71833&r=support Expected behavior: https://bugs.php.net/fix.php?id=71833&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=71833&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=71833&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=71833&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71833&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=71833&r=dst IIS Stability: https://bugs.php.net/fix.php?id=71833&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=71833&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=71833&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=71833&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=71833&r=mysqlcfg

« previous php.bugs (#199850) next »