php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51090 setTime on a DateTime object reapplying DateTime::sub()
Submitted: 2010-02-19 13:56 UTC Modified: 2010-02-20 10:56 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: aj at dl10design dot co dot uk Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.1 OS: Centos 5
Private report: No CVE-ID: None
 [2010-02-19 13:56 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-19 13:57 UTC] aj at dl10design dot co dot uk
Temporary workaround is to add

$datetime->sub(new DateInterval("P0D"));

after

$datetime->sub(new DateInterval("P2D"));
 [2010-02-20 10:56 UTC] jani@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

See bug #50916 (and try search before you submit anything..)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 09:01:28 2024 UTC