php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55253 DateTime::add() and sub() result -1 hour on objects with time zone type 2
Submitted: 2011-07-20 14:18 UTC Modified: 2011-11-24 17:13 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: danielc at analysisandsolutions dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.4SVN-2011-07-20 (SVN) OS: Ubuntu 10.04
Private report: No CVE-ID: None
 [2011-07-20 14:18 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-20 14:24 UTC] danielc@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-11-21 02:19 UTC] danielc@php.net
This is probably related to https://bugs.php.net/bug.php?id=60236
 [2011-11-24 17:13 UTC] derick@php.net
Automatic comment from SVN on behalf of derick
Revision: http://svn.php.net/viewvc/?view=revision&revision=319767
Log: - Fixed bug #60236 (TLA timezone dates are not converted properly from
  timestamp).
- Fixed bug #55253 (DateTime::add() and sub() result -1 hour on objects with
  time zone type 2).

And fixed some test cases.
 [2011-11-24 17:13 UTC] derick@php.net
This bug has been fixed in SVN.

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.


 [2011-11-24 17:13 UTC] derick@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: derick
 [2011-12-27 02:13 UTC] danielc@php.net
Automatic comment from SVN on behalf of danielc
Revision: http://svn.php.net/viewvc/?view=revision&revision=321419
Log: One less xfail since Bug 55253 was fixed.
 [2011-12-27 15:19 UTC] danielc@php.net
Automatic comment from SVN on behalf of danielc
Revision: http://svn.php.net/viewvc/?view=revision&revision=321437
Log: Another xfail resolved since Bug 55253 was fixed.
 [2011-12-27 16:49 UTC] danielc@php.net
Automatic comment from SVN on behalf of danielc
Revision: http://svn.php.net/viewvc/?view=revision&revision=321441
Log: Another xfail resolved since Bug 55253 was fixed.
 [2011-12-27 16:57 UTC] danielc@php.net
Automatic comment from SVN on behalf of danielc
Revision: http://svn.php.net/viewvc/?view=revision&revision=321442
Log: Resolve some xfails due to Bug 55253 being fixed. (merged from 54)
 [2011-12-27 19:43 UTC] danielc@php.net
Automatic comment from SVN on behalf of danielc
Revision: http://svn.php.net/viewvc/?view=revision&revision=321447
Log: Resolve more xfails due to Bug 55253 being fixed.
 [2011-12-28 01:12 UTC] danielc@php.net
Automatic comment from SVN on behalf of danielc
Revision: http://svn.php.net/viewvc/?view=revision&revision=321456
Log: Resolve the last of the xfails from Bug 55253.
 [2012-04-18 09:47 UTC] laruence@php.net
Automatic comment on behalf of derick
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d0a898d2a2852e697ea3d3bde6136993b75ad4f4
Log: - Fixed bug #60236 (TLA timezone dates are not converted properly from   timestamp). - Fixed bug #55253 (DateTime::add() and sub() result -1 hour on objects with   time zone type 2).
 [2012-07-24 23:38 UTC] rasmus@php.net
Automatic comment on behalf of derick
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d0a898d2a2852e697ea3d3bde6136993b75ad4f4
Log: - Fixed bug #60236 (TLA timezone dates are not converted properly from   timestamp). - Fixed bug #55253 (DateTime::add() and sub() result -1 hour on objects with   time zone type 2).
 [2012-09-30 00:06 UTC] lonnyk at gmail dot com
Just want to put an FYI in this report: It seems as though this fix caused bug 
#62561
 [2013-11-17 09:35 UTC] laruence@php.net
Automatic comment on behalf of derick
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d0a898d2a2852e697ea3d3bde6136993b75ad4f4
Log: - Fixed bug #60236 (TLA timezone dates are not converted properly from   timestamp). - Fixed bug #55253 (DateTime::add() and sub() result -1 hour on objects with   time zone type 2).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 06:01:30 2024 UTC