From:
Operating system: Ubuntu 10.04
PHP version: 5.3.2
Package: Date/time related
Bug Type: Bug
Bug description:Date::diff keeps subtracting after Date::sub
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 bug report at http://bugs.php.net/bug.php?id=51689&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=51689&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=51689&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=51689&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=51689&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=51689&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=51689&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=51689&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=51689&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=51689&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=51689&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=51689&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=51689&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=51689&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=51689&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51689&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=51689&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=51689&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=51689&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=51689&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=51689&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=51689&r=mysqlcfg