User:Marlin Woks/sandbox

Source: Wikipedia, the free encyclopedia.

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.[1] 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

Algorithm Julian Day Number
  Input: The date of interest: year, month, day
  Output: The Julian Day number
  a ← (14 - month) / 12
  yyear + 4800 - a
  mmonth + 12a - 3
  if year < 0 then
     yy + 1
  jdnday
  jdnjdn + (153m + 2) / 5
  jdnjdn + 365y
  jdnjdn + y / 4
  if Is_Gregorian_Date(year,month,day) then
     jdnjdn - y / 100
     jdnjdn + y / 400
     jdnjdn - 32045
  else
     jdnjdn - 32083
  return jdn
  • "←" denotes assignment. For instance, "largestitem" means that the value of largest changes to the value of item.
  • "return" terminates the algorithm and outputs the following value.