php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62561 DateTime add 'P1D' adds 25 hours
Submitted: 2012-07-13 21:41 UTC Modified: 2014-03-27 15:08 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: zach dot bailey at pardot dot com Assigned: stas
Status: Closed Package: Date/time related
PHP Version: 5.3.14 OS: Mac OS X 10.7.4
Private report: No CVE-ID:
 [2012-07-13 21:41 UTC] zach dot bailey at pardot dot com
Description:
------------
When a DateTime is constructed with a non-UTC timezone and one day is added, the 
time also jumps forward by an hour as well.

Test script:
---------------
$ts = new DateTime('@1341115200', new DateTimeZone('America/New_York'));

$dayFromTs = new DateTime('@1341115200', new DateTimeZone('America/New_York'));
$dayFromTs->add(new DateInterval('P1D'));

echo 'ts: '.$ts->format('Y-m-d H:i:s')."\n";
echo 'day from ts: '.$dayFromTs->format('Y-m-d H:i:s')."\n";

Expected result:
----------------
ts: 2012-07-01 04:00:00
day from ts: 2012-07-02 04:00:00

Actual result:
--------------
ts: 2012-07-01 04:00:00
day from ts: 2012-07-02 05:00:00

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-17 14:00 UTC] adam at lundrigan dot ca
Confirmed using PHP 5.3.16 (compiled from src) on RHEL 5.8

Failing PHPT test: https://github.com/adamlundrigan/php-src/blob/409bf5d888869aa2889d910af1b8edfe159febae/ext/date/tests/bug62561.phpt
 [2012-09-29 02:32 UTC] lonnyk at gmail dot com
This bug is the result of the fix for bug #55253 and bug #60236
 [2012-09-30 00:50 UTC] lonnyk at gmail dot com
This seems to be related to bug #62896
 [2012-09-30 04:34 UTC] lonnyk at gmail dot com
A potential fix is available https://github.com/php/php-src/pull/210
 [2012-10-01 03:21 UTC] stas@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

merged into 5.4
 [2012-10-01 03:21 UTC] stas@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: stas
 [2014-03-27 12:51 UTC] gckarakostas at gmail dot com
This still affects me in version 5.5.3+dfsg-1ubuntu2.2.
 [2014-03-27 13:43 UTC] gckarakostas at gmail dot com
My sincere apologies. That would be version 5.3.10-1ubuntu3.
 [2014-03-27 15:08 UTC] rasmus@php.net
Right, so as per http://php.net/releases you can see that 5.3.10 was released well before this bug was fixed.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 05:03:19 2014 UTC