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

 ID:                 52454
 Updated by:         [email protected]
 Reported by:        ben dot davies at stickyeyes dot com
 Summary:            Relative dates and getTimestamp increments by one
                     day
-Status:             Open
+Status:             Assigned
 Type:               Bug
 Package:            Date/time related
 Operating System:   Windows 7 Professional
 PHP Version:        5.3.3
-Assigned To:        
+Assigned To:        derick
 Block user comment: N



Previous Comments:
------------------------------------------------------------------------
[2010-07-27 11:46:01] ben dot davies at stickyeyes dot com

Description:
------------
If you create a DateTime object using a relative date string of "this
week +6 days", when calling getTimestamp on the datetime object, the
date is mysteriously increments by one day. However, if you seperately
modify the datetime using 'this week', then '+6 days', it works
correctly.



Where is the additional day comeing from, and why is it only applied
when calling format('U') DOESNT increment the datetime by 1 day. Wierd!



Here is a work around:



$endOfWeek = new DateTime();

$endOfWeek->modify('this week');

$endOfWeek->modify('+6 days');



echo $endOfWeek->format('Y-m-d H:m:s')."\n";

echo $endOfWeek->format('U')."\n";



/* Thar she blows! */

echo $endOfWeek->getTimestamp()."\n";



echo $endOfWeek->format('Y-m-d H:m:s')."\n";

Test script:
---------------
$endOfWeek = new DateTime();

$endOfWeek->modify('this week +6 days');



echo $endOfWeek->format('Y-m-d H:m:s')."\n";

echo $endOfWeek->format('U')."\n";



/* Thar she blows! */

echo $endOfWeek->getTimestamp()."\n";



echo $endOfWeek->format('Y-m-d H:m:s')."\n";



Expected result:
----------------
DateTime should stay the same after a call to getTimestamp (surely
getTimestamp should be safe from side effects)



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



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

Reply via email to