CALPAK
Calendar Calculations
CALPAK
is a C library which
computes various simple calendrical quantities.
These include converting
from daynumber/year to day/month/year format, calculating the time
difference between two dates, finding the day of the week of a given date,
and other feats.
Some common methods of marking the date include:

JED, the Julian Ephemeris Date, a count of days since
a long time ago;

YMD, for "year, month, day";

YJ, for "year, day number".
While there have been many calendars over the years, it
is instructive to contemplate just the crazy story of our
current "common" calendar. To this day, people disagree about
whether there was a year 0, although the Julian calendar
was a Roman invention, and Dionysius Exiguus, who gets the
blame for shifting the Julian calendar's starting date to
the birth year of Christ four hundred years afterwards, didn't
have an accurate idea of when that was.
There was a
controversial shift from the Julian to the Gregorian calendar,
which took place piecemeal throughout the Catholic
world, with several countries actually switching back and
forth more than once, and with England holding out on the
old system until after George Washington was born (which
means he was born on February 11 AND February 22).
People didn't agree on when the year started, so that January and
February, in particular, were a little murky about which
year they belonged to, and the year sometimes started
around March 22, near the vernal equinox.
There are a number of side issues, including

determining the day of the week of a given date;

determining the number of days between two dates;

the computation of the date of certain holidays;
Licensing:
The computer code and data files described and made available on this web page
are distributed under
the GNU LGPL license.
Languages:
CALPAK is available in
a C version and
a C++ version and
a FORTRAN90 version and
a MATLAB version and
a Python version.
Related Data and Programs:
ANALEMMA,
a C program which
evaluates the equation of time, a formula for the difference between
the uniform 24 hour day and the actual position of the sun,
by Brian Tung.
DATES,
a dataset directory which
contains lists of dates in various calendar systems.
DOOMSDAY,
a C library which
is given the year, month and day of a date, and uses
John Conway's doomsday algorithm to determine the corresponding day
of the week.
WEEKDAY,
a C library which
determines the day of the week for a given day.
Reference:

Anonymous,
A Correction; Welcome to 51,254,
The New York Times,
01 January 2000, Volume 149, Issue 51254.

James Barron,
What's in a Number? 143 Years of News,
The New York Times,
14 March 1995, Volume 144, Issue 50000.

Bonnie Blackburn, Leofranc HolfordStevens,
The Oxford Companion to the Year,
Oxford, 1999,
ISBN: 0192142313,
LC: CE73.B553.

Lewis Carroll (Charles Dodgson),
To Find the Day of the Week for Any Given Date,
Nature, 31 March 1887.

John Conway,
Tomorrow is the Day After Doomsday,
Eureka,
Volume 36, October 1973, pages 2831.

Peter DuffettSmith,
Practical Astronomy With Your Calculator,
Third Edition,
Cambridge University Press, 1996,
ISBN: 0521356997,
LC: QB62.5.D83.

Donald Knuth,
The Art of Computer Programming,
Volume 1, Fundamental Algorithms,
Third Edition,
AddisonWesley, 1997,
ISBN: 0201896834,
LC: QA76.6.K64.

Donald Knuth,
The Calculation of Easter,
Communications of the ACM,
Volume 5, Number 4, April 1962, pages 209210.

Gary Meisters,
Lewis Carroll's DayoftheWeek Algorithm,
Math Horizons,
November 2002, pages 2425.

Lance Latham,
Standard C Date/Time Library,
Programming the World's Calendars and Clocks,
Miller Freeman, 1998,
ISBN: 0879304960.

The New York Times,
Page One, 18961996, A Special Commemorative Edition Celebrating the
100th Anniversary of the Purchase of the New York Times by Adolph S Ochs,
Galahad Books, 1996,
ISBN: 0883659611,
LC: D411.P25.

The New York Times,
The Complete First Pages, 18512008,
Black Dog & Leventhal Publishers, 2008,
ISBN13: 9781579127497,
LC: D351.N53.

Thomas OBeirne,
Puzzles and Paradoxes,
Oxford University Press, 1965,
LC: QA95.O2.

Frank Parise, editor,
The Book of Calendars,
Gorgias, 2002,
ISBN: 1931956766,
LC: CE11.K4.

William Press, Brian Flannery, Saul Teukolsky, William Vetterling,
Numerical Recipes in FORTRAN: The Art of Scientific Computing,
Second Edition,
Cambridge University Press, 1992,
ISBN: 052143064X,
LC: QA297.N866.

Edward Reingold, Nachum Dershowitz,
Calendrical Calculations: The Millennium Edition,
Cambridge University Press, 2001,
ISBN: 0521777526,
LC: CE12.R45.

Edward Reingold, Nachum Dershowitz,
Calendrical Calculations I,
Software  Practice and Experience,
Volume 20, Number 9, September 1990, pages 899928.

Edward Reingold, Nachum Dershowitz, Stewart Clamen,
Calendrical Calculations, II: Three Historical Calendars,
Software  Practice and Experience,
Volume 23, Number 4, pages 383404, April 1993.

Edward Richards,
Mapping Time, The Calendar and Its History,
Oxford, 1999,
ISBN: 0198504136,
LC: CE11.R5.

Ian Stewart,
Easter is a Quasicrystal,
Scientific American,
Volume 284, Number 3, March 2001, pages 8083.

Daniel Zwillinger, editor,
CRC Standard Mathematical Tables and Formulae,
30th Edition,
CRC Press, 1996,
ISBN: 0849324793,
LC: QA47.M315.
Source Code:
List of Routines:


DIGIT_TO_CH returns the base 10 digit character corresponding to a digit.

I4_MAX returns the maximum of two I4's.

I4_MIN returns the smaller of two I4's.

I4_MODP returns the nonnegative remainder of I4 division.

I4_WRAP forces an I4 to lie between given limits by wrapping.

JED_TO_WEEKDAY computes the day of the week from a JED.

JED_TO_WEEKDAY_TEST tests JED_TO_WEEKDAY.

JED_WEEKDAY_VALUES returns the day of the week for Julian Ephemeris Dates.

R8_MOD returns the remainder of R8 division.

R8_NINT returns the nearest integer to an R8.

TIMESTAMP prints the current YMDHMS date as a time stamp.

WEEKDAY_TO_NAME_COMMON returns the name of a Common weekday.

WEEKDAY_VALUES returns the day of the week for various dates.

Y_COMMON_TO_ASTRONOMICAL converts a Common year to an Astronomical year.

YMD_TO_S_COMMON writes a Common YMD date into a string.

YMD_TO_WEEKDAY_COMMON returns the weekday of a Common YMD date.

YMD_TO_WEEKDAY_COMMON_TEST tests YMD_TO_WEEKDAY_COMMON.

YMD_TO_WEEKDAY_ENGLISH returns the weekday of an English YMD date.

YMD_TO_WEEKDAY_GREGORIAN returns the weekday of a Gregorian YMD date.

YMDF_COMPARE compares two YMDF dates.

YMDF_TO_JED_COMMON converts a Common YMDF date to a JED.

YMDF_TO_JED_ENGLISH converts an English YMDF date to a JED.

YMDF_TO_JED_GREGORIAN converts a Gregorian YMDF date to a JED.

YMDF_TO_JED_JULIAN converts a Julian YMDF date to a JED.
You can go up one level to
the C source codes.
Last revised on 05 July 2017.