Edit report at http://bugs.php.net/bug.php?id=50916&edit=1
ID: 50916 Comment by: Reported by: charlesb at itsmystuff dot com Summary: DateTime::sub repeats each time getTimestamp is called Status: Open Type: Bug Package: Date/time related Operating System: Windows Server 2003 SP2 PHP Version: 5.3.1 New Comment: I've attached a patch that is tested on Windows, although the code that needs to be changed appears to be universal. The patch also includes a .phpt that compares the resulting timestamps. The fix for this is a bit disconcerting for me, but as I'm not entirely familiar with the codebase, I didn't want to muck things up too much. Shouldn't the c function do_adjust_relative() in tm2unixtime.c be the one to clear the flags it uses after it applies changes? If we're clearing the flags in the calling functions, we're bound to miss more stuff like this one. Previous Comments: ------------------------------------------------------------------------ [2010-02-20 10:28:40] pontus dot alexander at gmail dot com This bug is confirmed to still be alive in snapshot "5.3-201002200930" compiled on Debian Linux. Reproduction code: $Time = new \DateTime('NOW'); $Month = new \DateInterval('P1Y'); var_dump($Time); // Correctly subtracted $Time->sub($Month); var_dump($Time); // Wrongly subtracted $Time->getTimestamp(); var_dump($Time); ------------------------------------------------------------------------ [2010-02-02 18:04:23] charlesb at itsmystuff dot com Description: ------------ Each time DateTime::getTimestamp is called, a previously called DateTime::sub value is applied. This does not occur with DateTime::add. Reproduce code: --------------- $work_time = new DateTime("2010-01-30 12:00:00"); $work_time->sub(new DateInterval("P7D")); $window_start = $work_time->getTimestamp(); echo date("Y-m-d H:i:s", $window_start) . "<br />"; $window_start = $work_time->getTimestamp(); echo date("Y-m-d H:i:s", $window_start) . "<br />"; Expected result: ---------------- 2010-01-23 12:00:00 2010-01-23 12:00:00 Actual result: -------------- 2010-01-16 12:00:00 2010-01-09 12:00:00 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=50916&edit=1