Bug #71833 [Opn->Csd]: DateTime - incorrect calculation for add()

From: Date: Tue, 15 Mar 2016 22:08:47 +0000
Subject: Bug #71833 [Opn->Csd]: DateTime - incorrect calculation for add()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199852@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71833&edit=1 ID: 71833 User updated by: troy_rudolph at bridge360 dot com Reported by: troy_rudolph at bridge360 dot com Summary: DateTime - incorrect calculation for add() -Status: Open +Status: Closed Type: Bug Package: Date/time related Operating System: windows and linux PHP Version: 5.6.19 Block user comment: N Private report: N New Comment: I think this is open to interpretation Previous Comments: ------------------------------------------------------------------------ [2016-03-15 21:03:23] troy_rudolph at bridge360 dot com 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 this bug report at https://bugs.php.net/bug.php?id=71833&edit=1

« previous php.bugs (#199852) next »