php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51689 Date::diff keeps subtracting after Date::sub
Submitted: 2010-04-29 00:54 UTC Modified: 2012-03-09 07:49 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: binarte at gmail dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.3.2 OS: Ubuntu 10.04
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: binarte at gmail dot com
New email:
PHP Version: OS:

 

 [2010-04-29 00:54 UTC] binarte at gmail dot com
Description:
------------
After executing a sub() on a DateTime object, for every call of diff(), both DateTime objects start getting subtracted by the value that was passed on sub().

Test script:
---------------
date_default_timezone_set('GMT');

$t1 = new DateTime('2010-01-01 00:00:00');
$t2 = new DateTime('2010-01-01 00:00:00');
$dif = new DateInterval('P1D');

$t2->sub($dif);
$t1->sub($dif);

for ($x = 0; $x < 3; $x++) {
	$t1->diff($t2);
	echo $t1->format("r\n");
	echo $t2->format("r\n");

	echo "\n";
}


Expected result:
----------------
Fri, 01 Jan 2010 00:00:00 +0000
Fri, 01 Jan 2010 00:00:00 +0000

Fri, 01 Jan 2010 00:00:00 +0000
Fri, 01 Jan 2010 00:00:00 +0000

Fri, 01 Jan 2010 00:00:00 +0000
Fri, 01 Jan 2010 00:00:00 +0000

Actual result:
--------------
Wed, 30 Dec 2009 00:00:00 +0000
Wed, 30 Dec 2009 00:00:00 +0000

Tue, 29 Dec 2009 00:00:00 +0000
Tue, 29 Dec 2009 00:00:00 +0000

Mon, 28 Dec 2009 00:00:00 +0000
Mon, 28 Dec 2009 00:00:00 +0000

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-29 01:11 UTC] derick@php.net
-Status: Open +Status: Feedback
 [2010-04-29 01:11 UTC] derick@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/
 [2012-03-09 07:38 UTC] php dot net at doppy dot nl
Result on php 5.3.6:
------------------
Thu, 31 Dec 2009 00:00:00 +0000
Thu, 31 Dec 2009 00:00:00 +0000

Thu, 31 Dec 2009 00:00:00 +0000
Thu, 31 Dec 2009 00:00:00 +0000

Thu, 31 Dec 2009 00:00:00 +0000
Thu, 31 Dec 2009 00:00:00 +0000
---------------
This is the expected result.

Recommend closing this.
 [2012-03-09 07:49 UTC] aharvey@php.net
-Status: Feedback +Status: Closed -Assigned To: +Assigned To: aharvey
 [2012-03-09 07:49 UTC] aharvey@php.net
Cheers; we'll call this fixed then.
 [2012-03-09 07:49 UTC] aharvey@php.net
-Assigned To: aharvey +Assigned To: derick
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 14:01:28 2025 UTC