Bug #60550 [Com]: strtotime adds compound string, subtracts wrong

From: Date: Wed, 21 Dec 2011 17:49:17 +0000
Subject: Bug #60550 [Com]: strtotime adds compound string, subtracts wrong
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-166031@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60550&edit=1 ID: 60550 Comment by: jayte dot boehler at bestnotes dot com Reported by: viewport2heaven at yahoo dot com Summary: strtotime adds compound string, subtracts wrong Status: Open Type: Bug Package: Date/time related Operating System: Windows 7 PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: The manual doesn't clarify how php processes a sequential set of number-based relative values, but it appears that the initial '+/-' does not dictate the direction of the entire sequence. If you continue in the negative direction with the string '-3 days -2 hours -3 minutes -4 seconds', it yields the correct diff... Previous Comments: ------------------------------------------------------------------------ [2011-12-17 04:02:03] viewport2heaven at yahoo dot com Description: ------------ --- From manual page: http://www.php.net/function.strtotime#refsect1-function.strtotime-parameters --- A string of '+1 day 2 hours 3 minutes 4 seconds' works. A string of '-1 day 2 hours 3 minutes 4 seconds' doesn't work. Test script: --------------- $time = strtotime('+3 days 2 hours 3 minutes 4 seconds') - time(); $expectedDiff = 3 * 24 * 60 * 60 + 2 * 60 * 60 + 3 * 60 + 4; $time = strtotime('-3 days 2 hours 3 minutes 4 seconds') - time(); $expectedDiff = 3 * 24 * 60 * 60 + 2 * 60 * 60 + 3 * 60 + 4; Expected result: ---------------- + and - should be the same. Actual result: -------------- + is correct. - is wrong. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60550&edit=1

« previous php.bugs (#166031) next »