php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54340 DateTime::add() method bug
Submitted: 2011-03-22 00:29 UTC Modified: 2011-03-22 09:33 UTC
From: 1cdecoder at gmail dot com Assigned: aharvey (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3.6 OS: Windows 7 x64
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: 1cdecoder at gmail dot com
New email:
PHP Version: OS:

 

 [2011-03-22 00:29 UTC] 1cdecoder at gmail dot com
Description:
------------
DateTime::add() method bug

Test script:
---------------
$date = new DateTime('first day of this month');
echo $date->format('Y-m-d H:i:sP');
$date->add(new DateInterval('P1D'));
echo $date->format('Y-m-d H:i:sP');

Expected result:
----------------
2011-03-01 01:17:31+02:00
2011-03-02 01:17:31+02:00 
Actual result:
--------------
2011-03-01 01:17:31+02:00
2011-03-01 01:17:31+02:00 


=================
====== BUT ======
=================

$date = new DateTime('first day of this month');
echo $date->format('Y-m-d H:i:sP');
$date->add(new DateInterval('P1M'));
echo $date->format('Y-m-d H:i:sP');

Expected result:
----------------
2011-03-01 01:17:31+02:00
2011-04-01 01:17:31+02:00 
Actual result:
--------------
2011-03-01 01:17:31+02:00
2011-04-01 01:17:31+02:00 



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-22 09:09 UTC] aharvey@php.net
-Package: *General Issues +Package: Date/time related
 [2011-03-22 09:27 UTC] aharvey@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: aharvey
 [2011-03-22 09:27 UTC] aharvey@php.net
Looks like we don't reset the DateTime object's timelib_rel_time
structure properly before altering it in add() (and sub(), for that
matter), and the first_last_day_of flag is causing issues.

Fix forthcoming.
 [2011-03-22 09:33 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&revision=309535
Log: Fix bug #54340 (DateTime::add() method bug).
 [2011-03-22 09:33 UTC] aharvey@php.net
-Status: Assigned +Status: Closed
 [2011-03-22 09:33 UTC] aharvey@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/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC