#47723 [Bgs]: strtotime(JD) provides wrong timestamp for some JD
| From: | berthier at imcce dot fr | Date: | Fri, 20 Mar 2009 14:16:33 +0000 |
| Subject: | #47723 [Bgs]: strtotime(JD) provides wrong timestamp for some JD | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-134926@lists.php.net to get a copy of this message | ||
ID: 47723
User updated by: berthier at imcce dot fr
Reported By: berthier at imcce dot fr
Status: Bogus
Bug Type: *Calendar problems
Operating System: ArchLinux, CentOS (x86_64)
PHP Version: 5.2.9
New Comment:
strtotime() is designed to try and parse a date from various weird
exotic formats, any English textual datetime description as it is
written in the php doc. So I don't understand why it should not return
false (or a valid timestamp) for all julian days (which are not
considered as textual datetime). This behaviour is (at least for me) a
problem as it returns a wrong information which is not useful.
Previous Comments:
------------------------------------------------------------------------
[2009-03-20 01:59:49] scottmac@php.net
You can use parse_date() to see what it is doing here, its taking the
digits directly before the period as the day of the year and the part
after as the year.
I'm not sure why its not happening on your OpenSuse machine, but I get
this behaviour on all the 5.2.9 builds I tested and I don't see a
problem with what its doing.
strtotime() is designed to try and parse a date from various weird
exotic formats.
------------------------------------------------------------------------
[2009-03-19 18:28:54] berthier at imcce dot fr
Description:
------------
For the first 365 days of each millennium, the function strtotime()
applied on a Julian Day provides a Unix timestamp whereas it should not.
Moreover, the Unix timestamp is wrong and always ranges between
110638652400 and 110670188400.
This bug exists for php 5.2.9 on ArchLinux 2009-02 kernel 2.6.28
x86_64
and also for php 5.2.6 on CentOS 5.2 kernel 2.6.18 x86_64. It does not
exist for php 5.2.6 on OpenSuse 11.1 kernel 2.6.27 i686.
Reproduce code:
---------------
<?php
$epoch_0 = 2400000.5476;
for ($i=0; $i<=100000; $i++) {
$epoch = $epoch_0 + $i;
if (($timestamp = strtotime($epoch)) === FALSE) {
echo $epoch." == not a timestamp!\n";
} else {
echo $epoch." == timestamp = ".$timestamp." ; JD =
".unixtojd($timestamp)."\n";
}
}
?>
Expected result:
----------------
2400000.5476 == not a timestamp!
2400001.5476 == not a timestamp!
2400002.5476 == not a timestamp!
...
2400365.5476 == not a timestamp!
2400366.5476 == not a timestamp!
2400367.5476 == not a timestamp!
Actual result:
--------------
2400000.5476 == not a timestamp!
2400001.5476 == timestamp = 110638652400 ; JD = 3721128
2400002.5476 == timestamp = 110638738800 ; JD = 3721129
...
2400365.5476 == timestamp = 110670102000 ; JD = 3721492
2400366.5476 == timestamp = 110670188400 ; JD = 3721493
2400367.5476 == not a timestamp!
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47723&edit=1