/**************************************************************************
Convert a y-m-d (y in 1..3000?, m in 1..12, d in 1..31) to a Julian
Date.
**************************************************************************/
integer proc jd(integer y, integer m, integer d)
return (( 1461 * ( y + 4800 + ( m - 14 ) / 12 ) ) / 4 +
( 367 * ( m - 2 - 12 * ( ( m - 14 ) / 12 ) ) ) / 12 -
( 3 * ( ( y + 4900 + ( m - 14 ) / 12 ) / 100 ) ) / 4 +
d - 32075)
end
/**************************************************************************
Convert a Julian date to the corresponding Gregorian y-m-d.
**************************************************************************/
proc gd(integer jd, var integer y, var integer m, var integer d)
integer i, l, n, j
l = jd + 68569
n = ( 4 * l ) / 146097
l = l - ( 146097 * n + 3 ) / 4
i = ( 4000 * ( l + 1 ) ) / 1461001 //(that's 1,461,001)
l = l - ( 1461 * i ) / 4 + 31
j = ( 80 * l ) / 2447
d = l - ( 2447 * j ) / 80
l = j / 11
m = j + 2 - ( 12 * l )
y = 100 * ( n - 49 ) + i + l //(that's a lower-case L)
end
proc main()
integer x, y
x = jd(1970, 1, 1)
y = jd(2020, 1, 15)
warn(y - x)
end
Shows: 18276
Based on this:
Julian Day Numbers
by Peter Meyer
Introduction
History
Astronomical Sytem
Modified Julian Day Number
Lillian Day Number
Computation
Introduction
Astronomers and chronologists use a system of numbering days called Julian
days or Julian day numbers. The temporal sequence of days is mapped onto the
sequence of integers, -2, -1, 0, 1, 2, 3, etc. This makes it easy to
determine the number of days between two days (just subtract one Julian day
number from the other).
For example a solar eclipse is said to have been seen at Ninevah on Julian
day 1,442,454 and a lunar eclipse is said to have been observed at Babylon
on Julian day number 1,566,839 (these numbers correspond to the Julian
Calendar dates -763-03-23 and -423-10-09 respectively). Thus the lunar
eclipse occurred 124,384 days after the solar eclipse.
Generally speaking, an integer date is any system of assigning a one-to-one
correspondence between the days of our experience (more strictly, solar
days) and the integers. Such systems differ only in the day chosen to
correspond to day 0 or day 1. For example, in some applications NASA uses
the Truncated Julian Date, which is the number of days since midnight on
1968-05-24 (at which time the Apollo missions to the Moon were underway).
Other starting dates popular with computer programmers are, or have been,
1601-01-01 (Gregorian), 1900-01-01, 1901-01-01 and 1980-01-01. The choice is
usually a consequence of the temporal precision required (days to
microseconds), the application period (a decade, a century, a millennium,
etc.) and the number of bytes available for storing the date.
The system of Julian days should not be confused with the simpler system of
the same name which associates a date with the number of days elapsed since
January 1st of the same year (according to which 2000-12-31 is day 366 ù of
the year 2000).
History
The Julian Day number system was invented by Joseph Justus Scaliger (born
1540-08-05 J in Agen, France, died 1609-01-21 J in Leiden, Holland), who
during his life immersed himself in Greek, Latin, Persian and Jewish
literature. His invention (in 1583) of the Julian day number system is
considered by some the foundation of the science of chronology.
Although the term Julian Calendar derives from the name of Julius Caesar,
the term Julian day number probably does not. Most say that this system was
named, not after Julius Caesar, but after its inventor's father, Julius
Caesar Scaliger (1484-1558). Perhaps it was simply named after the Julian
Calendar.
The younger Scaliger combined three traditionally recognized temporal cycles
of 28, 19 and 15 years to obtain a great cycle, the Scaliger cycle, or
Julian period, of 7980 years (7980 is the least common multiple of 28, 19
and 15). According to the Encyclopedia Brittanica:
The length of 7,980 years was chosen as the product of 28 times 19 times
15; these, respectively, are the numbers of years in the so-called solar
cycle of the Julian calendar in which dates recur on the same days of
the week; the lunar or Metonic cycle, after which the phases of the Moon
recur on a particular day in the solar year, or year of the seasons; and
the cycle of indiction, originally a schedule of periodic taxes or
government requisitions in ancient Rome.
The first Scaliger cycle began with Year 1 on -4712-01-01 (Julian) and will
end after 7980 years on 3267-12-31 (Julian), which is 3268-01-22
(Gregorian). 3268-01-01 J is the first day of Year 1 of the next Scaliger
cycle.
Astronomical Sytem
Little mention seems to be made as to whether Joseph Scaliger regarded
-4712-01-01 J as day 0 or as day 1 in the first Julian period. Astronomers
adopted this system and adapted it to their own purposes, and they took noon
GMT -4712-01-01 as their zero point. For astronomers a day begins at noon
and runs until the next noon (so that the nighttime falls conveniently
within one "day"). Thus they defined the Julian day number of a day as the
number of days (or part of a day) elapsed since noon GMT (or more exactly,
UTC) on January 1st, 4713 B.C., in the Proleptic Julian Calendar. Thus the
Julian day number of noon GMT on -4712-01-01 (Julian), or more casually, the
Julian day number of -4712-01-01 itself, is 0. (Note that 4713 B.C. is the
year -4712 according to the astronomical year numbering.) The Julian day
number of 1996-03-31 is 2,450,174 ù meaning that on 1996-03-31 2,450,174
days had elapsed since -4712-01-01 (or more exactly, that at noon on
1996-03-31 2,450,174 days had elapsed since noon on -4712-01-01).
Scaliger preceded the astronomers in introducing the notion of decimal
times, designating midnight as .00, 6 a.m. as .25, midday as .50 and 6 p.m.
as .75, thus allowing easier calculation involving dates and times.
Astronomers, as noted above, preferred to use .00 to mean midday and .50 to
mean midnight.
Modified Julian Day Number
This was not to the liking of all scholars using the Julian day number
system, in particular, historians. For chronologists who start "days" at
midnight, the zero point for the Julian day number system is 00:00 at the
start of -4712-01-01 J, and this is day 0. This means that 2000-01-01 G is
2,451,545 JD.
Since most days within about 150 years of the present have Julian day
numbers beginning with "24", Julian day numbers within this 300-odd-year
period can be abbreviated. In 1975 the convention of the modified Julian day
number was adopted:
Given a Julian day number JD, the modified Julian day number MJD is defined
as MJD = JD - 2,400,000.5. This has two purposes:
Days begin at midnight rather than noon.
For dates in the period from 1859 to about 2130 only five digits need to
be used to specify the date rather than seven.
MJD 0 thus corresponds to JD 2,400,000.5, which is twelve hours after noon
on JD 2,400,000 = 1858-11-16. Thus MJD 0 designates the midnight of November
16th/17th, 1858, so day 0 in the system of modified Julian day numbers is
the day 1858-11-17.
Lilian Day Number
This concept is similar to that of the Julian day number. It is named after
Aloysius Lilius (an advisor to Pope Gregory XIII) who, together with his
brother, is said to have invented the Gregorian Calendar. The Lilian day
number is defined as "the number of days since 14 October 1582". This was
the time of the introduction of the Gregorian Calendar, when it was decreed
by Pope Gregory XIII that the day following 4 October 1582 (which is 5
October 1582, in the Julian Calendar) would thenceforth be known as 15
October 1582. Strictly speaking, the definition should be "the number of
days since 14 October 1582 in the Proleptic Gregorian Calendar". Thus 15
October 1582 (Gregorian) is Lilian day 1 (the first day of the Gregorian
Calendar), 16 October 1582 is Lilian day 2, and so on.
The relation between Julian day numbers and Lilian day numbers is: LD = JD -
2,299,160
Computation
Mathematicians and programmers have naturally interested themselves in
mathematical and computational algorithms to convert between Julian day
numbers and Gregorian dates.
In 1968 in a letter to the editor of Communications of the ACM (CACM, volume
11, number 10, October 1968, p.657) Henry F. Fliegel and Thomas C. Van
Flandern presented such an algorithm.
The Julian day (jd) is computed from Gregorian day, month and year (d, m, y)
as follows:
jd = ( 1461 * ( y + 4800 + ( m - 14 ) / 12 ) ) / 4 +
( 367 * ( m - 2 - 12 * ( ( m - 14 ) / 12 ) ) ) / 12 -
( 3 * ( ( y + 4900 + ( m - 14 ) / 12 ) / 100 ) ) / 4 +
d - 32075
Division is to be understood as in integer arithmetic, with the remainders
discarded.
Converting from the Julian day to the Gregorian day is performed thus:
l = jd + 68569
n = ( 4 * l ) / 146097
l = l - ( 146097 * n + 3 ) / 4
i = ( 4000 * ( l + 1 ) ) / 1461001 (that's 1,461,001)
l = l - ( 1461 * i ) / 4 + 31
j = ( 80 * l ) / 2447
d = l - ( 2447 * j ) / 80
l = j / 11
m = j + 2 - ( 12 * l )
y = 100 * ( n - 49 ) + i + l (that's a lower-case L)
Days are integer values in the range 1-31, months are integers in the range
1-12, and years are positive or negative integers. This algorithm is valid
only for dates from -4900-03-01 G onward when converting from a Julian day
number to a date, or from -4800-03-01 G onward (when converting from a date
to a Julian day number). It should be noted that these algorithms are valid
only in the Gregorian Calendar and the Proleptic Gregorian Calendar (after
the dates given above). They do not handle dates in the Julian Calendar.
This algorithm is implemented in two C functions in DATLIB, a library of C
functions for converting and manipulating calendar dates.
A completely different calendar date / Julian day number computational
algorithm (developed by the present writer) is implemented as two other C
functions in the same function library. This algorithm handles dates in the
Julian Calendar as well as dates in the Gregorian Calendar. In addition it
is valid for any calendar date with a year within the range of about
-5,800,000 to about +5,800,000.
In each of these algorithms Julian day number 0 corresponds to -4713-11-24 G
(= -4712-01-01 J).