|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-03-02 16:36 UTC] tomas dot brastavicius at quantum dot lt
[2011-03-02 16:58 UTC] derick@php.net
-Status: Open
+Status: Bogus
[2011-03-02 16:58 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 23 14:00:01 2025 UTC |
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$