#51090 [Com]: setTime on a DateTime object reapplying DateTime::sub()
| From: | aj at dl10design dot co dot uk | Date: | Fri, 19 Feb 2010 13:57:44 +0000 |
| Subject: | #51090 [Com]: setTime on a DateTime object reapplying DateTime::sub() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-147868@lists.php.net to get a copy of this message | ||
ID: 51090
Comment by: aj at dl10design dot co dot uk
Reported By: aj at dl10design dot co dot uk
Status: Open
Bug Type: Date/time related
Operating System: Centos 5
PHP Version: 5.3.1
New Comment:
Temporary workaround is to add
$datetime->sub(new DateInterval("P0D"));
after
$datetime->sub(new DateInterval("P2D"));
Previous Comments:
------------------------------------------------------------------------
[2010-02-19 13:56:13] aj at dl10design dot co dot uk
Description:
------------
When using set time after modifying the date by using sub, the sub is
re-applied as well.
Reproduce code:
---------------
date_default_timezone_set('Europe/London');
$datetime = new DateTime('2010-02-19 14:52:10');
$datetime->sub(new DateInterval("P2D"));
// Date should now be 2010-02-17
echo $datetime->format("Y-m-d H:i:s") . "<br />";
$datetime->setTime(15,0,0);
// Date and time should now be 2010-02-17 15:00:00
// BUT it is 2010-02-15 15:00:00
echo $datetime->format("Y-m-d H:i:s");
Expected result:
----------------
Only the time should have be changed
Actual result:
--------------
Day and date are changed.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=51090&edit=1