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 examination yields that gregoriantojd is requiring the minus 
sign to be used for years as a direct replacement for "BC". Thus, 
2AD==2, 1AD==1, 1BC==-1, 2BC==-2, etc. Fine. This is not indicated in 
the manual. Also, the manual states that the earliest year is 4714BC. 
This is an error

When the defined date of Jan. 1, 4713 BC (which is supposed to be "day

zero" of Julian Days, by definition) is entered into each function, -
4713-01-01 for gregoriantojd and -4712-01-01 for GtoJD, BOTH yield '38'

rather than the expected 'zero'.

Plugging in today's date yields:
2454544 for gregoriantojd;
2454545 for GtoJD.


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

[2008-03-18 22:49:37] reidw at rawsound dot com

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.

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

[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