ID:               44474
 User updated by:  reidw at rawsound dot com
 Reported By:      reidw at rawsound dot com
 Status:           Open
 Bug Type:         Calendar related
 Operating System: Darwin 9.2
 PHP Version:      5.2.5
 New Comment:

Further research shows that the code for GtoJD to convert a Gregorian 
date to julian days may be off.

But, the function gregoriantojd still gives gross errors for zero and 
negative years.


Previous Comments:
------------------------------------------------------------------------

[2008-03-18 22:21:29] reidw at rawsound dot com

Description:
------------
The function gregroiantojd() returns the wrong value. This was also 
tested with PHP 5.2.2 on Linux FC3 and PHP 5.1.2 on Windows Server 2003

with the same results. Results are off by one day for positive years, 
and further off for zero and negative years. By definition, when using

negative years rather than a suffix the pattern should be: ..., -2, -1,

0, 1, 2, ... . Year 2 corresponds to 2AD, year 1 corresponds to 1AD, 
year 0 corresponds to 1BC, and year -1 corresponds to 2BC, etc. 
Information can be found from the links in the PHP manual. Code for 
comparison is taken from those links and given below.

Reproduce code:
---------------
built-in:
echo gregoriantojd(3,16,1)."\n";
echo gregoriantojd(3,16,0)."\n";
echo gregoriantojd(3,16,-1);


reproduced from PHP manual links:
echo GtoJD(3,16,1)."\n";
echo GtoJD(3,16,0)."\n";
echo GtoJD(3,16,-1);
function GtoJD($m,$d,$y)
{
  return (int) (((int) ( 1461 * ( $y + 4800 + ($m-14) / 12 ) ) / 4) +
    ((int) ( 367 * ( $m - 2 - 12 * ( ($m-14) / 12 ) ) ) / 12) -
    ((int) ( 3 * (int)( ( $y + 4900 + ($m-14) / 12 ) / 100 ) ) / 4) +
    $d - 32075);
}



Expected result:
----------------
The expected results are (from the reproduced code):
1721501
1721137
1720771





Actual result:
--------------
Actual results (from the built-in gregoriantojd()):
1721500
0
1721135






------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=44474&edit=1

Reply via email to