php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48963 Unexpected results when converting from Gregorian Date to Julian Day and back
Submitted: 2009-07-17 17:26 UTC Modified: 2009-07-17 17:35 UTC
From: satovey at yahoo dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.10 OS: Windows XP Sp3 Xamp Apache
Private report: No CVE-ID: None
 [2009-07-17 17:26 UTC] satovey at yahoo dot com
Description:
------------
When converting Gregorian date to Julian day and then back to the Gregorian date, unexpected results can occur if the year being two digits such as (26) is entered as a four digit (0026). 

This produces a four year difference of 1461 days.

The quick solution to this is to enter four digit years such as 0026 as a literal '0026'.



Reproduce code:
---------------
$month=3; $day=18; $year=26;
		$gregToJd=gregoriantojd($month,$day,$year);
		$gregDateFromJd=JdToGregorian($gregToJd);
		echo "month: $month, day: $day, year: $year <br>";
		echo "JulianDay from gregorian date: $gregToJd <br>";
		echo "GregorianDate from julian day: $gregDateFromJd <br>";
		$month=3; $day=18; $year=0026;
		$gregToJd=gregoriantojd($month,$day,$year);
		$gregDateFromJd=JdToGregorian($gregToJd);
		echo "month: $month, day: $day, year: $year <br>";
		echo "JulianDay from gregorian date: $gregToJd <br>";
		echo "GregorianDate from julian day: $gregDateFromJd <br>";
		$month=3; $day=18; $year='0026';
		$gregToJd=gregoriantojd($month,$day,$year);
		$gregDateFromJd=JdToGregorian($gregToJd);
		echo "month: $month, day: $day, year: $year <br>";
		echo "JulianDay from gregorian date: $gregToJd <br>";
		echo "GregorianDate from julian day: $gregDateFromJd <br>";


Expected result:
----------------
One would expect the following output from the code:

month: 3, day: 18, year: 26
JulianDay from gregorian date: 1730633
GregorianDate from julian day: 3/18/26
month: 3, day: 18, year: 22
JulianDay from gregorian date: 1730633
GregorianDate from julian day: 3/18/26
month: 3, day: 18, year: 0026
JulianDay from gregorian date: 1730633
GregorianDate from julian day: 3/18/26 

Actual result:
--------------
The actual output of the code is as follows:

month: 3, day: 18, year: 26
JulianDay from gregorian date: 1730633
GregorianDate from julian day: 3/18/26
month: 3, day: 18, year: 22
JulianDay from gregorian date: 1729172
GregorianDate from julian day: 3/18/22
month: 3, day: 18, year: 0026
JulianDay from gregorian date: 1730633
GregorianDate from julian day: 3/18/26 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-17 17:35 UTC] jani@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


$ php -r '$i = 0026; var_dump($i);'
int(22)

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 22:01:31 2024 UTC