User:Marlin Woks/sandbox

The following algorithm show an implementation of the Julian Day Number computation. It is important to remember that this works for valid dates only. So, for instance, in most countries the dates between 5th October 1582 and 14th October 1582, inclusive, are not valid dates since these days never existed. They were removed to bring the civil calendar in line with the astronomical seasons and to herald the change from the Julian calendar to the Gregorian calendar. This algorithm correctly shows that 4th October 1582 is Julian Day Number 2299160, and the 15th October 1582 is the following day number, 2299161. This algorithm also correctly identifies Jan 1 4713 BCE as Julian Day Number 0 (zero), and thus this algorithm is correct for all valid dates between Jan 1 4713 BCE to Jan 1 4713 CE. As noted above, integer division is assumed throughout

Input: The date of interest: year, month, day Output: The Julian Day number

a ← (14 - month) / 12 y ← year + 4800 - a m ← month + 12a - 3 if year < 0 then y ← y + 1 jdn ← day jdn ← jdn + (153m + 2) / 5 jdn ← jdn + 365y jdn ← jdn + y / 4 if Is_Gregorian_Date(year,month,day) then jdn ← jdn - y / 100 jdn ← jdn + y / 400 jdn ← jdn - 32045 else jdn ← jdn - 32083 return jdn