The Western calendrical system -- known as the Julian calendar and consisting of a year of 12 months and of 365 days with an extra day every fourth year -- was established by Julius Caesar (following the advice of the Alexandrian astronomer Sosigenes) in 46 B.C. The extra day may not have been added consistently until A.D. 8, during the reign of Augustus. Subsequently, this calendar became widespread as a result of the expansion of the Roman Empire. The system of numbering years Anno Domini was instituted in A.D. 525 by the Roman abbot Dionysius Exiguus.
The Julian calendar assumes that the average length of a year is 365 days and six hours (since one day is added every four years). The length of the year assumed in the Julian calendar exceeds the current true value by about 11 minutes, resulting in an error of about three days every 400 years. Thus, as the centuries passed the Julian calendar became increasingly inaccurate with respect to the solar year as defined in terms of the solstices and the equinoxes. This was especially troubling to the Church because it affected the determination of the date of Easter, which by the sixteenth century was slipping gradually into summer. To resolve these problems, the calendar was reformed in 1582 on the authority of Pope Gregory XIII, and the modified calendar is called the Gregorian calendar.
In this article, I'll present a C function which converts any date within an 11-million-year period in either the Gregorian calendar or the Julian calendar into a unique long int, a number in the range of approximately -2,000,000,000 through 2,000,000,000. A function is also given for conversion of a long int back into a date in one of the calendars. This permits conversion between dates in the Julian and Gregorian calendars and provides a basis for other date-manipulation functions. The date-conversion functions given in this article are used in a general C-function library that I developed, the Dolphin C Toolkit.
Universal Date Conversion
According to the Gregorian reform, ten days (or more exactly, dates) were omitted from the c lendar. It was decreed that the day following October 4, 1582 (which was October 5, 1582 in the old calendar) would thenceforth be known as October 15, 1582. In addition, the rule for leap years was changed. In the Julian calendar, a year is a leap year if it is divisible by 4. In the Gregorian calendar, a year is a leap year if it is divisible by 4, with the added criterion that years divisible by 100 must also be divisible by 400. Thus the years 1600 and 2000 are leap years, but 1700, 1800, 1900, and 2100 are not. Finally, it was decreed that new rules for the determination of the date of Easter would be adopted.
Day Numbers
Astronomers use a system of numbering days called Julian-day numbers. The term "Julian-day number" (unlike the term "Julian calendar") does not derive from the name of Julius Caesar. This numbering system is said to have been named after Julius, the father of its inventor. The astronomical system of Julian-day numbers should not be confused with the simpler system of the same name, which associates a date with the number of days elapsed since January first of the same year (according to which December 31, 1993 is Day 365).