#43056 [NEW]: unixtojd() behavior is ill-specified
| From: | vorlon at debian dot org | Date: | Sun, 21 Oct 2007 06:22:17 +0000 |
| Subject: | #43056 [NEW]: unixtojd() behavior is ill-specified | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-118773@lists.php.net to get a copy of this message | ||
From: vorlon at debian dot org
Operating system: all
PHP version: 5.2.4
PHP Bug Type: Calendar related
Bug description: unixtojd() behavior is ill-specified
Description:
------------
The calendar extension's unixtojd() function is described in the php
manual as simply:
unixtojd Convert Unix timestamp to Julian Day
No further explanation is given for how a Julian Day is defined in this
case. However, if we use the definition given at
<http://www.decimaltime.hynes.net/dates.html#jdn>
which appears to be the
normal astronomical meaning of a Julian Day, a Julian Day should be
measured from noon GMT (or UT).
The problem is that the unixtojd() function uses php_localtime_r() to
convert a given UNIX timestamp to a time_t struct - which means the base
Gregorian date used for the conversion is calculated in the local timezone,
not in GMT. This function should use php_gmtime_r() instead.
This problem was detected when running the PHP testsuite with TZ=UTC set -
the ext/calendar/tests/unixtojd.phpt test expects a value that is only
returned in a timezone west of GMT!
(Separately, I see nowhere that the 12h offset is taken into account, so
in practice all unixtojd() results are currently calculated from midnight
in the local timezone.)
Reproduce code:
---------------
<?php
setenv('TZ=America/Los_Angeles');
echo unixtojd(1000000000). "\n";
?>
Expected result:
----------------
2452162
Actual result:
--------------
2452161
--
Edit bug report at http://bugs.php.net/?id=43056&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43056&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43056&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43056&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43056&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=43056&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=43056&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=43056&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=43056&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=43056&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=43056&r=support
Expected behavior: http://bugs.php.net/fix.php?id=43056&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=43056&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=43056&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=43056&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43056&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=43056&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=43056&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=43056&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=43056&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=43056&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=43056&r=mysqlcfg