From: Operating system: Ubuntu 11.04 PHP version: 5.3.5 Package: Date/time related Bug Type: Bug Bug description:unexpected strtotime() behavior with unix timestamps
Description: ------------ I'm working on a payment processor which unfortunately has to take several types of date input, as a result I need to test if a date I'm being passed is already a unix timestamp. For the most part strtotime() will return false when passed a timestamp. There are a few edge cases where it will return another timestamp sometime after year 2400 or before 2000. If this is actually the expected behavior it might be worthwhile to throw a warning in the documentation about passing strtotime() unix timestamps Test script: --------------- $errors = 0; $end_date = strtotime('January 1st 2020'); $start_date = strtotime('January 1st 2001'); $bad_years = array(); while ($start_date < $end_date){ if (strtotime($start_date) !== false){ echo date ('Y-m-d', $start_date) . ' generates ' . strtotime($start_date) . ' ' . date('Y-m-d', strtotime($start_date)) . "\n"; $bad_years[] = date('Y', strtotime($start_date)); $errors++; } $start_date += 86400; } print_r(array_unique($bad_years)); echo "$errors errors generated\n"; Expected result: ---------------- sam.heller@sam:/var/www/development/api/app/scripts$ php test.php Array ( ) 0 errors generated sam.heller@sam:/var/www/development/api/app/scripts$ Actual result: -------------- sam.heller@sam:/var/www/development/api/app/scripts$ php test.php 2001-09-14 generates 51442009244 3600-02-18 2001-09-15 generates -62163017947 0000-02-18 2001-09-25 generates 64064790099 4000-02-18 2001-09-26 generates -49540237092 0400-02-18 ... ... ... 2019-05-22 generates -24294654070 1200-02-18 2019-05-23 generates 177669838738 7600-02-18 2019-06-02 generates -11671873215 1600-02-18 2019-06-03 generates 190292619593 8000-02-18 Array ( [0] => 3600 [1] => 0000 [2] => 4000 [3] => 0400 [4] => 6800 [5] => 0800 [6] => 7200 [8] => 1200 [9] => 7600 [11] => 8000 [12] => 4400 [14] => 8400 [15] => 4800 [17] => 5200 [18] => 1600 [20] => 2000 [22] => 2400 [23] => 8800 [25] => 9200 [26] => 5600 [28] => 9600 [29] => 6000 [31] => 6400 [32] => 2800 [34] => 3200 ) 1007 errors generated sam.heller@sam:/var/www/development/api/app/scripts$ -- Edit bug report at http://bugs.php.net/bug.php?id=54048&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=54048&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=54048&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=54048&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=54048&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54048&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=54048&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=54048&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=54048&r=needscript Try newer version: http://bugs.php.net/fix.php?id=54048&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=54048&r=support Expected behavior: http://bugs.php.net/fix.php?id=54048&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=54048&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=54048&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=54048&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54048&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=54048&r=dst IIS Stability: http://bugs.php.net/fix.php?id=54048&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=54048&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=54048&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=54048&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=54048&r=mysqlcfg