From: reidw at rawsound dot com Operating system: Darwin 9.2 PHP version: 5.2.5 PHP Bug Type: Calendar related Bug description: GregorianToJD wrong return value
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 bug report at http://bugs.php.net/?id=44474&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44474&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44474&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44474&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=44474&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=44474&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=44474&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=44474&r=needscript Try newer version: http://bugs.php.net/fix.php?id=44474&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=44474&r=support Expected behavior: http://bugs.php.net/fix.php?id=44474&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=44474&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=44474&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=44474&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44474&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=44474&r=dst IIS Stability: http://bugs.php.net/fix.php?id=44474&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=44474&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=44474&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=44474&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=44474&r=mysqlcfg