note 73458 deleted from function.strtotime by derick
| From: | derick@php.net | Date: | Sun, 15 Jul 2007 12:36:37 +0000 |
| Subject: | note 73458 deleted from function.strtotime by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-128549@lists.php.net to get a copy of this message | ||
Note Submitter: cesoid at yahoo dot com
----
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.