Bug #77941 [NEW]: strtotime "next <weekday>" are off by one for dates parsed from calendar week

From: Date: Thu, 25 Apr 2019 09:25:25 +0000
Subject: Bug #77941 [NEW]: strtotime "next <weekday>" are off by one for dates parsed from calendar week
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220605@lists.php.net to get a copy of this message
From: mail at cebe dot cc Operating system: Linux PHP version: 7.3.4 Package: Date/time related Bug Type: Bug Bug description:strtotime "next <weekday>" are off by one for dates parsed from calendar week Description: ------------ when working on a date parsed from calendar week from the pattern {YYYY}W{WW}, e.g. "2019W16" strtotime returns the date of Monday in the calendar week 16 in the year 2019, which is 2019-04-15. When this is combinated with a "next <weekday>" e.g. "2019W16 next friday", the result is one off, in this case 2019-04-18, which is Thursday of that week, not Friday. Giving "2019-04-15 next friday" gives the correct date: 2019-04-19. According to my test script, this is broken since PHP 5.2, while working fine in 5.1: https://3v4l.org/0s4Ns Test script: --------------- <?php // see also https://3v4l.org/0s4Ns if (function_exists('date_default_timezone_set')) date_default_timezone_set("UTC"); echo "works as expected:\n"; echo date("Y-m-d H:i:s", strtotime("2019W14")) . " should be 2019-04-01\n"; echo date("Y-m-d H:i:s", strtotime("2019W15")) . " should be 2019-04-08\n"; echo date("Y-m-d H:i:s", strtotime("2019W16")) . " should be 2019-04-15\n\n"; echo "off by one:\n"; echo date("Y-m-d H:i:s", strtotime("2019W16 next tuesday")) . " should be 2019-04-16\n"; echo date("Y-m-d H:i:s", strtotime("2019W16 next wednesday")) . " should be 2019-04-17\n"; echo date("Y-m-d H:i:s", strtotime("2019W16 next thursday")) . " should be 2019-04-18\n"; echo date("Y-m-d H:i:s", strtotime("2019W16 next friday")) . " should be 2019-04-19\n"; echo date("Y-m-d H:i:s", strtotime("2019W16 next saturday")) . " should be 2019-04-20\n"; echo date("Y-m-d H:i:s", strtotime("2019W16 next sunday")) . " should be 2019-04-21\n"; echo date("Y-m-d H:i:s", strtotime("2019W16 next monday")) . " should be 2019-04-22\n\n"; echo "works as expected:\n"; echo date("Y-m-d H:i:s", strtotime("2019-04-15 next monday")) . " should be 2019-04-22\n"; echo date("Y-m-d H:i:s", strtotime("2019-04-15 next friday")) . " should be 2019-04-19\n"; echo date("Y-m-d H:i:s", strtotime("2019-04-15 next thursday")) . " should be 2019-04-18\n"; Expected result: ---------------- see above. Actual result: -------------- see above. -- Edit bug report at https://bugs.php.net/bug.php?id=77941&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77941&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77941&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77941&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=77941&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=77941&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=77941&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=77941&r=needscript Try newer version: https://bugs.php.net/fix.php?id=77941&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=77941&r=support Expected behavior: https://bugs.php.net/fix.php?id=77941&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=77941&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=77941&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=77941&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77941&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=77941&r=dst IIS Stability: https://bugs.php.net/fix.php?id=77941&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=77941&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=77941&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=77941&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=77941&r=mysqlcfg

« previous php.bugs (#220605) next »