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

From: Date: Tue, 15 Mar 2016 23:35:07 +0000
Subject: Bug #71833 [Csd->Nab]: DateTime - incorrect calculation for add()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199854@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 Updated by: requinix@php.net Reported by: troy_rudolph at bridge360 dot com Summary: DateTime - incorrect calculation for add() -Status: Closed +Status: Not a bug 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: It's a daylight savings thing. With America/Chicago, 3/12 12am was after daylight savings last year and before it this year, but since UTC doesn't do daylight savings there's an hour lost when you juggle the timezones and add a date interval that way. If you did the same thing on the other side of the transition then you would see an hour gained instead. Previous Comments: ------------------------------------------------------------------------ [2016-03-15 22:08:46] troy_rudolph at bridge360 dot com I think this is open to interpretation ------------------------------------------------------------------------ [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 (#199854) next »