note 73458 added to function.strtotime

From: Date: Fri, 23 Feb 2007 20:15:52 +0000
Subject: note 73458 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-123788@lists.php.net to get a copy of this message
The offset used in safestrtotime() is wrong by one hour (too big). This becomes obvious when you take the timestamp from the function and feed it into the date() function. For example, putting 1/1/1902 12:00:00 am into safestrtotime() will give you 2149072096 (in EST). date('n/j/Y g:i:s a', 2149072096) then returns 1/1/1902 1:00:00 am. The real number following 0x80000000 should be 1566848, not 1570448. The number 1566848 is consistent with the correct calculation of time between 1902 Jan 1 00:00:00, and 1901 Dec 13 20:45:54. This should be 18 days (to Dec 31), 3 hours, 14 minutes and 8 seconds. 18 * 86400 + 14 * 60 + 8. It may be more intuitive to subtract 68 years worth of seconds, but both methods are easily verifiable (and surprisingly went unverified for almost two years) by feeding the timestamp into the date() function as done above. A sidenote to this is that the original safestrtotime() comment included another error; the earliest date and time representable with a signed 32 bit unix timestamp is not 13/12/1901 20:45:54, but 13/12/1901 20:45:52. This caused my own calculation to be off by two seconds initially. ---- Server IP: 64.71.164.2 Probable Submitter: 12.197.12.50 ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- https://master.php.net/note/edit/73458 Del: integrated -- https://master.php.net/note/delete/73458/integrated Del: useless -- https://master.php.net/note/delete/73458/useless Del: bad code -- https://master.php.net/note/delete/73458/bad+code Del: spam -- https://master.php.net/note/delete/73458/spam Del: non-english -- https://master.php.net/note/delete/73458/non-english Del: in docs -- https://master.php.net/note/delete/73458/in+docs Del: other reasons-- https://master.php.net/note/delete/73458 Reject -- https://master.php.net/note/reject/73458 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123788) next »