Bug #51689 [Opn->Fbk]: Date::diff keeps subtracting after Date::sub

From: Date: Wed, 28 Apr 2010 23:11:18 +0000
Subject: Bug #51689 [Opn->Fbk]: Date::diff keeps subtracting after Date::sub
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-150016@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=51689&edit=1

 ID:               51689
 Updated by:       derick@php.net
 Reported by:      binarte at gmail dot com
 Summary:          Date::diff keeps subtracting after Date::sub
-Status:           Open
+Status:           Feedback
 Type:             Bug
 Package:          Date/time related
 Operating System: Ubuntu 10.04
 PHP Version:      5.3.2

 New Comment:

Please try using this snapshot:

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

  http://windows.php.net/snapshots/


Previous Comments:
------------------------------------------------------------------------
[2010-04-29 00:54:55] 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


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51689&edit=1


Thread (4 messages)

« previous php.bugs (#150016) next »