php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43056 unixtojd() behavior is ill-specified
Submitted: 2007-10-21 06:22 UTC Modified: 2008-11-03 01:00 UTC
From: vorlon at debian dot org Assigned:
Status: No Feedback Package: Date/time related
PHP Version: 5.2.4 OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-10-21 06:22 UTC] vorlon at debian dot org
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-26 23:47 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2008-10-27 03:43 UTC] vorlon at debian dot org
No, I'm thankfully free of maintaining PHP packages now, I have no intention of chasing CVS tarballs to check whether you've fixed the code.
 [2008-11-03 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-07-13 13:02 UTC] a dot e at inne dot pl
I also find it very frustrating, you would expect that you make   gmmktime(0,0,0,2009,30,10) or somthing like this, then convert it to JD and back to unix time and get the same not local time :/

Is that a bug that is going to be fixed or maybe documentation could be updated so that people would understand what will happen?

Thanks a million

Art
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 12:01:27 2024 UTC