From: slomo at sonarkollektiv dot de Operating system: Mac OS X 10.4.8 PHP version: 5.2.0 PHP Bug Type: *General Issues Bug description: strtotime() produces unexpected results while using Day of week items
Description: ------------ I was looking for a neat solution for the task "get the date for a given weeknumber and weekyear". I thought I got it, but there is a strange behaviour if (and only if) week no. is 1 and 4th of January is already a monday. See my code to reproduce the results, it's quite confusing. The idea was: - 4th of January is always in week no. 1 - add the missing weeks - make it a monday of that week acording to the GNU Date Input Formats syntax descibed at http://www.gnu.org/software/tar/ manual/html_node/tar_114.html#SEC114 So either me or PHP still does not get it right. Reproduce code: --------------- function MondayOfWeek($year, $week) { return strtotime("$year-01-04 UTC + " . ($week-1) . ' week last monday'); } for ($y = 1998; $y < 2012; $y++) { for ($w = 1; $w < 53; $w++) { $start = MondayOfWeek($y, $w); $end = strtotime("+6 day", $start); echo "KW $w/$y: " . gmstrftime('%A, %x %X', $start) . ' - ' . gmstrftime('%A, %x %X', $end) . " "; echo '- reverse check (week/year): ' . gmstrftime('%V/%G', $start) . "\n"; if ($w != gmstrftime('%V', $start) || $y != gmstrftime('%G', $start)) { echo "ERROR!\n"; } } echo "<hr>\n"; } Expected result: ---------------- accurate results for every week number and year with always the same behaviour ... Actual result: -------------- if week no. is 1 and 4th of January is already a monday, the function returns timestamps for the "previous week". -- Edit bug report at http://bugs.php.net/?id=40271&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40271&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40271&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40271&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=40271&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=40271&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=40271&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=40271&r=needscript Try newer version: http://bugs.php.net/fix.php?id=40271&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=40271&r=support Expected behavior: http://bugs.php.net/fix.php?id=40271&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=40271&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=40271&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=40271&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40271&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=40271&r=dst IIS Stability: http://bugs.php.net/fix.php?id=40271&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=40271&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=40271&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=40271&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=40271&r=mysqlcfg