[net.sources] gregorian calendar and julian date

mckeeman@wanginst.UUCP (William McKeeman) (12/30/85)

This is a program to complete partial calendar information.  It relates
the year, month, day, day of the week, week of the month, day of the year 
and julian day.  Given all this information, it will confirm the relation.
Given part of this information, it will attempt to fill in the missing data.
It combines a number of previously published programs into one.  Since it
is sensitive to the range of integer arithmetic a set of tests results is
included.  Please send bugs and suggestions to the author.

W. M. McKeeman            mckeeman@WangInst
Wang Institute            decvax!wanginst!mckeeman
Tyngsboro MA 01879

-------------cut here--------------------------cut here----------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	gregorian.1
#	makefile
#	gregorian.c
#	test.exe
#	test.author
# This archive created: Mon Dec 30 14:33:58 1985
export PATH; PATH=/bin:$PATH
echo shar: extracting "'gregorian.1'" '(6815 characters)'
if test -f 'gregorian.1'
then
	echo shar: will not over-write existing file "'gregorian.1'"
else
sed 's/^	X//' << \SHAR_EOF > 'gregorian.1'
	X.TH GREG 1 local
	X.SH NAME
	Xgreg \- compute details of Gregorian calendar
	X.SH SYNTAX
	X.B "greg Year Month DayOfMonth [DayOfWeek WeekOfMonth DayOfYear JulianDay]"
	X.SH SYNOPSIS
	X.I Greg
	Xprovides calendar information.
	XIt approximates the functionality of unix cal except that the information
	Xis provided in a way that is appropriate for use in other programs 
	Xrather than visual display.
	X.PP
	XThe internal function "gregorian" is designed to be used as a component
	Xof other programs.
	X.SH DESCRIPTION
	XThe program is invertible in the sense of a logic programming predicate.
	XThat is, inputs with positive values are checked for consistency;
	Xmissing inputs (indicated by otherwise illegal value 0) are given
	Xthe correct positive value if possible.
	X.PP
	XIf all the output is correct, the program will exit with 0.
	X.PP
	XIf the input cannot be reconciled, the program will exit with 1.
	X.PP
	XIf the input leaves the output indeterminate, the program will exit with 2.
	X.PP
	XIf the C implementation cannot support the calculation because of
	Xarithmetic precision, the program will exit with 3.
	X.SH PARAMETERS
	XThere are seven related inputs.
	XInputs 1-3 are required.
	XIf inputs 4-7 are omitted, zero is assumed for each.
	X.PP
	XThe
	X.I Year
	Xis an integer >=
	X.I 1582
	X(the year the Gregorian calendar was adopted).
	X.PP
	XThe
	X.I Month
	Xis an integer between
	X.I 1
	Xand
	X.I 12.
	X.PP
	XThe
	X.I DayOfMonth
	Xis an integer between 
	X.I 1
	Xand
	X.I 28, 29, 30
	Xor
	X.I 31
	Xdepending on the month.
	X.PP
	XThe
	X.I DayOfWeek
	Xis an integer between
	X.I 1
	Xand
	X.I 7
	Xcorresponding to
	X.I
	XSunday, Monday, ... Saturday.
	XIt is the column position of
	Xthe date in the conventional monthly calendar tableau.
	X.PP
	XThe
	X.I WeekOfMonth
	Xis an integer between
	X.I 1
	Xand
	X.I 6
	Xcorresponding to weeks in the calendar month.
	XIt is the row position of the date
	Xin the conventional monthly calendar tableau.
	XThe first of the month is always in week
	X.I 1.
	X.PP
	XThe
	X.I DayOfYear
	Xis an integer between
	X.I 1
	Xand
	X.I 365
	Xor
	X.I 366
	X.PP
	XThe
	X.I JulianDay
	Xis an integer >=
	X.I
	X2299161,
	Xcorresponding to
	X.I
	X15 October, 1582.
	XIt measures the time in days from 1 Jan 4713 BC (Julian calendar).
	X(There is nothing theoretically wrong with smaller -- even negative -- values 
	Xexcept they are not within the range of interesting Gregorian calendars.)
	XEach julian day starts at noon, GMT of the corresponding day of the Gregorian
	Xcalendar.
	X.bp
	XThere are four patterns of input for the seven parameters
	Xthat can possibly give a correct result.
	XThey are given below.
	XP signifies positive integer (an input).
	X? signifies either 0 (an unknown) or a positive integer (an input).
	X.nf
	X.ta 1i +2n +2n +2n +2n +2n 
	X	P	P	P	?	-- year
	X	P	?	P	?	-- month of year
	X	P	?	?	?	-- day of month
	X	?	?	P	?	-- day of week
	X	?	?	P	?	-- week of month
	X	?	P	?	?	-- day of year
	X	?	?	?	P	-- julian day
	X.fi
	X.SH FILES
	Xnone
	X.SH METHOD
	X.PP
	XThe Gregorian Calendar was adopted starting October 15, 1582
	X(September 14, 1752 in Britain and her colonies).
	XDates prior to adoption were in the Julian Calendar system
	X(no relation to julian days).
	XDates before the conversion are denoted OS (old system);
	Xdates after the conversion are denoted NS (new system).
	XThis program will extrapolate Gregorian dates back to 1 AD
	Xalthough it will issue a warning (inconsistent) for dates prior to the
	Xadoption of the Gregorian calendar.
	X1 BC OS immediately preceded 1 AD OS (no year 0)
	Xso the algorithms are invalid, even for extrapolation, prior to 1 AD.
	X.PP
	XThe algorithms, some from the references below, are tableless.
	XThe collection given here is valid from January 1, 1 AD NS.
	XThe algorithms, which depend on a number of
	X.I ad hoc
	Xfunctions over integers,
	Xare cryptic but the alternative of using tables does not help much.
	XThe notation is C.
	XLogical values are to be interpreted as 1 == true and 0 == false.
	XWhere it is supposed that the names of the functions
	Xare not sufficiently mnemonic an italic comment is appended.
	XThe code in gregorian.c is algebraically simplified where
	Xpossible when the functions below are back substituted into
	Xother defining formulas.
	X.nf
	X.ta 2i
	X
	X    LeapsB4(y) ==  97*(y-1)/400    \fI	leap years between 1 AD and year y\fP
	X
	X    Leap(y) == LeapsB4(y+1) - LeapsB4(y)
	X
	X    DaysIn(y) == 365+Leap(y)   \fI	days in year y\fP
	X
	X    DaysB4(m, y) == 3055*(m+2)/100 - 91 - (m>2)*(2-Leap(y))  \fI  1 <= m <=13\fP
	X
	X    DaysIn(y) == DaysB4(13, y)   \fI	alternative for days in year y\fP
	X
	X    DaysIn(m, y) == ((m == 2) ? 28+Leap(y) : 30+(m==1 || m%5%3 != 1))
	X 
	X    DayOf(y, m, d) == DaysB4(m, y) + d
	X.I
	X	day of year y counting from 1 Jan
	X
	X    MonthOf(y, yd) == (yd + (yd>59+Leap(y))*(2-Leap(y)) + 91)*100/3055 - 2
	X
	X    DayOf(y, yd) == (yd + (yd>59+Leap(y))*(2-Leap(y)) + 91)*100%3055/100 + 1
	X
	X    JulianDaysB4(y) == (y-1)*365 + LeapsB4(y) + 1721425
	X
	X    JulianDay(y, m, d) == JulianDaysB4(y) + DayOf(y, m, d)
	X
	X    Year(jd) == 400*(jd - 1721425)/146097 + 1
	X.I
	X	year in which julian day jd occurs
	X
	X    DayOf(jd) == jd - JulianDaysB4(Year(jd))
	X.I
	X	given the julian day jd, day of year from 1 Jan
	X
	X    WeekDay(jd) = (jd+1)%7+1    \fI	Sunday = 1, etc\. \fP
	X
	X    Week(dm, dw) = (13 + dm - dw)/7
	X.I
	X	week of month from day of month and day of week
	X.fi
	X.SH LIMITS
	XInputs are converted by atoi which does not check for non-digits.
	XThe julian day is, by definition, bounded from below by 2299161
	X(15 October, 1582).
	XThe program will fail for implementations of C with
	X.I
	Xsizeof (long int) < 4.
	XFor 32 bit machines arithmetic overflow will cause the 
	Xalgorithm to fail after julian day 7090078 (November 15, 14699).
	XSimilarly, the year and date are bounded from below by October 15, 1582
	Xand from above by December 31, 14700.
	XThe program extrapolates backward correctly to January 1, 1 AD NS
	Xbut reports the input is "inconsistent" prior to October 15, 1582.
	XThe Gregorian calendar is identical to the Julian Calendar during
	Xmost of the third century AD.
	XThe Gregorian calendar will incorrectly place the vernal equinox 
	Xapproximately three days by the year 14700.
	X.SH SEE ALSO
	X1. Any almanac, under calendar, perpetual.
	X(Note the World Almanac (1985, 1986) gives a julian day incorrect by one). 
	X.PP
	X2. Any encyclopedia, under calendar.
	X.PP
	X3. The Astronomical Ephemeris (any year)
	X.PP
	X3. CAL(1).  The information supplied by greg corresponds to cal starting
	XSeptember 14, 1752 AD.
	X.PP
	X4. Elmore, Perpetual Calendar, Am.J.Phys.44,3 (May 1976) pp 482-3.
	X.PP
	X5. Fliegel & Van Flandern, A Machine Algorithm for Processing Calendar
	XDates, (letter to the editor) CACM 11,10 (October 1968) pg. 657.
	X.PP
	X6. Stone, Tableless Date Conversion. Algorithm 398. Collected Algorithms from
	Xthe CACM (rcvd Jan 1970) and a Remark by Robertson (rcvd Dec 1970).
	X.PP
	X7. Tantzen, Conversions Between Calendar Date and Julian Day Number,
	XAlgorithm 199. Collected Algorithms from the CACM (August 1963).
	X.PP
	X8. Uspensky & Heaslet, Elementary Number Theory, McGraw-Hill, (1939) p.206-221.
SHAR_EOF
if test 6815 -ne "`wc -c < 'gregorian.1'`"
then
	echo shar: error transmitting "'gregorian.1'" '(should have been 6815 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'makefile'" '(677 characters)'
if test -f 'makefile'
then
	echo shar: will not over-write existing file "'makefile'"
else
sed 's/^	X//' << \SHAR_EOF > 'makefile'
	X# Makefile for "greg" -- W. M. McKeeman -- Wang Institute -- 1985
	X# Assuming you have unshared all of this,
	X# make greg
	X# will compile greg and
	X# make man
	X# will produce the manual page.
	X# make test
	X# will compare greg's output with some results prepared by the author
	X
	Xgreg:	gregorian.c
	X	cc -o greg gregorian.c
	X
	Xtest:	greg test.exe test.author
	X	test.exe > test.results
	X	diff test.results test.author
	X	echo "all tests passed"
	X
	Xman:	gregorian.1
	X	nroff -man gregorian.1 > gregorian.man
	X
	Xlaser:	gregorian.1
	X	iroff -man gregorian.1
	X
	Xfornet:	gregorian.1 makefile gregorian.c test.exe
	X	test.exe > test.author
	X	@shar -a gregorian.1 makefile gregorian.c test.exe test.author > fornet
	X
SHAR_EOF
if test 677 -ne "`wc -c < 'makefile'`"
then
	echo shar: error transmitting "'makefile'" '(should have been 677 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'gregorian.c'" '(4894 characters)'
if test -f 'gregorian.c'
then
	echo shar: will not over-write existing file "'gregorian.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'gregorian.c'
	X/************************************************************************/
	X/* Program:     greg                                                    */
	X/* Purpose:     compute and verify information for Gregorian calendar   */
	X/* Copyright:   W. M. McKeeman -- placed in public domain -- 12/1985    */
	X/* Input:       year, month, day                                        */
	X/*              day of month week & year, week of month, julian day.    */
	X/*              input values are zero (meaning "to be computed") or     */
	X/*              positive integers (meaning "to be checked and used")    */
	X/* Output:      consistent positive values for input:                   */
	X/*              return 0 if all output is valid,                        */
	X/*              return 1 if input is inconsistent,                      */
	X/*              return 2 if input is incomplete,                        */
	X/*              return 3 if int or long int is too short.               */
	X/* Example:                                                             */
	X/*   y = 1985; m = 12; d = 10; wd = 0; wk = 0; yd = 0;   jd = 0;        */
	X/*   gregorian(&y, &m, &d, &wd, &wk, &yd, &jd) returns 0 and leaves:    */
	X/*   y = 1985; m = 12; d = 10; wd = 3; wk = 2; yd = 344; jd = 2446410;  */
	X/* Method:        tableless.  see man page                              */
	X/************************************************************************/
	X#include <stdio.h>
	X
	X#define success 0
	X#define inconsistent 1
	X#define incomplete 2
	X#define systemfailure 3
	X
	X#define defined(e) ((e) != 0)
	X#define makeconsistent(v1, v2) \
	X    {if (defined(v1) && (v1) != (v2)) return inconsistent; else (v1) = (v2);}
	X
	X#define AD0001Jan00        1721425L
	X#define AD1582Oct15        2299161L
	X#define AD14699Nov15       7090078L
	X
	Xint
	Xgregorian(year, month, day0month, day0week, week0month, day0year, julianDay)
	Xint *year, *month, *day0month, *day0week, *week0month, *day0year;
	Xlong int *julianDay;                            /* 7 significant digits */
	X{
	X    int d, w, m, y, ly, leaps;
	X    long int td, jd;
	X    if defined(*julianDay) {
	X        if (*julianDay > AD14699Nov15 && sizeof (long int) <= 4)
	X            return systemfailure;
	X        if (*julianDay <= AD0001Jan00) return inconsistent;
	X        y = 400*(*julianDay - AD0001Jan00)/146097 + 1;
	X        makeconsistent(*year, y);
	X        d = *julianDay - (146097L*(y-1)/400 + AD0001Jan00);
	X        makeconsistent(*day0year, d);
	X    }
	X
	X    if (!defined(*year)) return incomplete; else y = *year;
	X    if (y > 14700 && sizeof (long int) <= 4) return systemfailure;
	X    leaps = 97L*(y-1)/400;
	X    ly = 97L*y/400-leaps;
	X
	X    if (!defined(*day0year)) {
	X        if (!defined(*month)) return incomplete;
	X        if (!defined(*day0month)) {
	X            if (!defined(*day0week)||!defined(*week0month))return incomplete;
	X            *day0month = 7*(*week0month-1) + *day0week - 
	X                (y+leaps+3055L*(*month+2)/100-84-(*month>2)*(2-ly))%7;
	X        }
	X        *day0year = 3055L*(*month+2)/100 - 91 + *day0month - (*month>2)*(2-ly);
	X    }
	X
	X    td = (*day0year + (*day0year>59+ly)*(2-ly) + 91)*100L;
	X    m = td/3055 - 2;
	X    makeconsistent(*month, m);
	X    d = td%3055/100 + 1;
	X    makeconsistent(*day0month, d);
	X
	X    jd = 146097L*(y-1)/400 + AD0001Jan00 + *day0year;
	X    makeconsistent(*julianDay, jd);
	X    w = (jd+1)%7 + 1;
	X    makeconsistent(*day0week, w);
	X    w = (13 + *day0month - *day0week)/7;
	X    makeconsistent(*week0month, w);
	X
	X    return *month > 12 || *julianDay < AD1582Oct15 || *day0month >
	X        (*month == 2 ? 28+ly : 30+(*month == 1 || *month%5%3 != 1));
	X}
	X
	Xmain(argc, argv)                                /* driver for gregorian */
	Xint argc; char *argv[];
	X{
	X    int r, i, p[7];
	X    long int jd;                                /* 7 significant digits */
	X
	X    if (sizeof (long int) < 4 || sizeof (int) < 2) r = systemfailure;
	X    else if (argc > 8) r = inconsistent;        /* too many inputs      */
	X    else if (argc < 4) r = incomplete;          /* need y m d at least  */
	X    else {
	X        r = success;
	X        for (i=1;i<=6;i++) {
	X            p[i] = i < argc ? atoi(argv[i]) : 0;
	X            if (p[i] < 0) r = inconsistent;     /* no negative input    */
	X        }
	X        jd = argc == 8 ? atol(argv[7]) : 0L;    /* julian day is (long) */
	X        if (r != inconsistent)
	X            r = gregorian(&p[1], &p[2], &p[3], &p[4], &p[5], &p[6], &jd);
	X    }
	X
	X    switch (r) {
	X    case inconsistent:
	X        puts("greg: input does not describe a valid gregorian date");
	X    case success:
	X        printf("%d %d %d %d %d %d %ld\n", p[1],p[2],p[3],p[4],p[5],p[6],jd);
	X        break;
	X    case incomplete:
	X        puts("greg: insufficient information");
	X        puts("usage: greg year month day [day0week week0month day0year jd]");
	X        break;
	X    case systemfailure:
	X        puts("greg: insufficient precision in either (int) or (long int)");
	X        break;
	X    }
	X    exit(r);
	X}
SHAR_EOF
if test 4894 -ne "`wc -c < 'gregorian.c'`"
then
	echo shar: error transmitting "'gregorian.c'" '(should have been 4894 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'test.exe'" '(6906 characters)'
if test -f 'test.exe'
then
	echo shar: will not over-write existing file "'test.exe'"
else
sed 's/^	X//' << \SHAR_EOF > 'test.exe'
	X#!/bin/sh
	X# tests of program greg  (Bourne shell script)
	X
	Xcal 12 1985 # delete this line if you don't have cal to run
	Xecho smoke test
	Xecho greg 1985	12	10  # birthday for this program
	Xgreg 1985	12	10  # birthday for this program
	Xecho $?
	X
	Xecho test input validity checking capability
	Xecho 1985	12	10	  3	2	   344	2446410
	Xgreg 1985	12	10	  3	2	   344	2446410
	Xecho $?
	X
	Xecho test various input inversions
	Xecho 1985	 0	 0	  0	0	   344	0
	Xgreg 1985	 0	 0	  0	0	   344	0
	Xecho $?
	Xecho 0		 0	 0	  0	0	   0	2446410
	Xgreg 0		 0	 0	  0	0	   0	2446410
	Xecho $?
	Xecho 1985	12	 0	  3	1	   0	
	Xgreg 1985	12	 0	  3	1	   0	
	Xecho $?
	Xecho 1985	12	 0	  3	2	   0	
	Xgreg 1985	12	 0	  3	2	   0	
	Xecho $?
	Xecho 1985	12	 0	  3	3	   0	
	Xgreg 1985	12	 0	  3	3	   0	
	Xecho $?
	Xecho 1985	12	 0	  3	4	   0	
	Xgreg 1985	12	 0	  3	4	   0	
	Xecho $?
	Xecho 1985	12	 0	  3	5	   0	
	Xgreg 1985	12	 0	  3	5	   0	
	Xecho $?
	Xecho 1985	12	 0	  3	6	   0	
	Xgreg 1985	12	 0	  3	6	   0	
	Xecho $?
	Xecho 1985	12	 0	  3	7	   0	
	Xgreg 1985	12	 0	  3	7	   0	
	Xecho $?
	Xecho 1985	12	 0	  7	6	   0	
	Xgreg 1985	12	 0	  7	6	   0	
	Xecho $?
	Xecho 1985	11	 0	  1	1	   0	
	Xgreg 1985	11	 0	  1	1	   0	
	Xecho $?
	Xecho 1985	12	10	  3	0	   344	
	Xgreg 1985	12	10	  3	0	   344	
	Xecho $?
	Xecho 1985	12	10	  0	2	   0	
	Xgreg 1985	12	10	  0	2	   0	
	Xecho $?
	Xecho 1985	12	10	  0	3	   0	
	Xgreg 1985	12	10	  0	3	   0	
	Xecho $?
	Xecho 1985	12	10	  2	0	   0	
	Xgreg 1985	12	10	  2	0	   0	
	Xecho $?
	Xecho 1985	12	10	  0	0	   344	
	Xgreg 1985	12	10	  0	0	   344	
	Xecho $?
	Xecho 1985	12	 0	  0	0	   344	
	Xgreg 1985	12	 0	  0	0	   344	
	Xecho $?
	Xecho 1985	 0	10	  0	0	   344	
	Xgreg 1985	 0	10	  0	0	   344	
	Xecho $?
	Xecho 1985	12	10	  0	0	   345	
	Xgreg 1985	12	10	  0	0	   345	
	Xecho $?
	X
	Xecho test first of a bunch of months
	Xecho 1985	 1	 1	  0	0	   0	
	Xgreg 1985	 1	 1	  0	0	   0	
	Xecho $?
	Xecho 1985	 2	 1	  0	0	   0	
	Xgreg 1985	 2	 1	  0	0	   0	
	Xecho $?
	Xecho 1985	 3	 1	  0	0	   0	
	Xgreg 1985	 3	 1	  0	0	   0	
	Xecho $?
	Xecho 1985	 4	 1	  0	0	   0	
	Xgreg 1985	 4	 1	  0	0	   0	
	Xecho $?
	Xecho 1985	 5	 1	  0	0	   0	
	Xgreg 1985	 5	 1	  0	0	   0	
	Xecho $?
	Xecho 1985	 6	 1	  0	0	   0	
	Xgreg 1985	 6	 1	  0	0	   0	
	Xecho $?
	Xecho 1985	 7	 1	  0	0	   0	
	Xgreg 1985	 7	 1	  0	0	   0	
	Xecho $?
	Xecho 1985	 8	 1	  0	0	   0	
	Xgreg 1985	 8	 1	  0	0	   0	
	Xecho $?
	Xecho 1985	 9	 1	  0	0	   0	
	Xgreg 1985	 9	 1	  0	0	   0	
	Xecho $?
	Xecho 1985	10	 1	  0	0	   0	
	Xgreg 1985	10	 1	  0	0	   0	
	Xecho $?
	Xecho 1985	11	 1	  0	0	   0	
	Xgreg 1985	11	 1	  0	0	   0	
	Xecho $?
	Xecho 1985	12	 1	  0	0	   0	
	Xgreg 1985	12	 1	  0	0	   0	
	Xecho $?
	X
	Xecho test funny leap years
	Xcal 3 2000 # delete this line if you don't have cal to run
	Xecho 2000	 3	 1	  0	0	   0	
	Xgreg 2000	 3	 1	  0	0	   0	
	Xecho $?
	Xcal 3 1900 # delete this line if you don't have cal to run
	Xecho 1900	 3	 1	  0	0	   0	
	Xgreg 1900	 3	 1	  0	0	   0	
	Xecho $?
	X
	Xecho test first and last day
	Xcal 1984 # delete this line if you don't have cal to run
	Xecho 1984	 1	 1	  0	0	   0	
	Xgreg 1984	 1	 1	  0	0	   0	
	Xecho $?
	Xecho 1984	12	31	  0	0	   0	
	Xgreg 1984	12	31	  0	0	   0	
	Xecho $?
	X
	Xecho violate various calendar limitations
	Xecho 1984	 0	 0	  0	0	   1	
	Xgreg 1984	 0	 0	  0	0	   1	
	Xecho $?
	Xecho 1984	 0	 0	  0	0	   366	
	Xgreg 1984	 0	 0	  0	0	   366	
	Xecho $?
	Xecho 1984	 0	 0	  0	0	   367	
	Xgreg 1984	 0	 0	  0	0	   367	
	Xecho $?
	Xecho 1984	13	 1	  0	0	   0	
	Xgreg 1984	13	 1	  0	0	   0	
	Xecho $?
	X
	Xecho thoroughly test a February
	Xecho 1984	 2	 1	  0	0	   0	
	Xgreg 1984	 2	 1	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	 2	  0	0	   0	
	Xgreg 1984	 2	 2	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	 3	  0	0	   0	
	Xgreg 1984	 2	 3	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	 4	  0	0	   0	
	Xgreg 1984	 2	 4	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	 5	  0	0	   0	
	Xgreg 1984	 2	 5	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	 6	  0	0	   0	
	Xgreg 1984	 2	 6	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	 7	  0	0	   0	
	Xgreg 1984	 2	 7	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	 8	  0	0	   0	
	Xgreg 1984	 2	 8	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	 9	  0	0	   0	
	Xgreg 1984	 2	 9	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	10	  0	0	   0	
	Xgreg 1984	 2	10	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	11	  0	0	   0	
	Xgreg 1984	 2	11	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	12	  0	0	   0	
	Xgreg 1984	 2	12	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	13	  0	0	   0	
	Xgreg 1984	 2	13	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	14	  0	0	   0	
	Xgreg 1984	 2	14	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	15	  0	0	   0	
	Xgreg 1984	 2	15	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	16	  0	0	   0	
	Xgreg 1984	 2	16	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	17	  0	0	   0	
	Xgreg 1984	 2	17	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	18	  0	0	   0	
	Xgreg 1984	 2	18	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	19	  0	0	   0	
	Xgreg 1984	 2	19	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	20	  0	0	   0	
	Xgreg 1984	 2	20	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	21	  0	0	   0	
	Xgreg 1984	 2	21	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	22	  0	0	   0	
	Xgreg 1984	 2	22	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	23	  0	0	   0	
	Xgreg 1984	 2	23	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	24	  0	0	   0	
	Xgreg 1984	 2	24	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	25	  0	0	   0	
	Xgreg 1984	 2	25	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	26	  0	0	   0	
	Xgreg 1984	 2	26	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	27	  0	0	   0	
	Xgreg 1984	 2	27	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	28	  0	0	   0	
	Xgreg 1984	 2	28	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	29	  0	0	   0	
	Xgreg 1984	 2	29	  0	0	   0	
	Xecho $?
	Xecho should fail
	Xecho 1985	 2	29	  0	0	   0	
	Xgreg 1985	 2	29	  0	0	   0	
	Xecho $?
	Xecho 1984	 2	30	  0	0	   0	
	Xgreg 1984	 2	30	  0	0	   0	
	Xecho $?
	Xecho test around March 1
	Xecho 1984	 0	 0	  0	0	   59	
	Xgreg 1984	 0	 0	  0	0	   59	
	Xecho $?
	Xecho 1984	 0	 0	  0	0	   60	
	Xgreg 1984	 0	 0	  0	0	   60	
	Xecho $?
	Xecho 1984	 0	 0	  0	0	   61	
	Xgreg 1984	 0	 0	  0	0	   61	
	Xecho $?
	Xecho 1984	 2	 0	  0	0	   61	
	Xgreg 1984	 2	 0	  0	0	   61	
	Xecho $?
	X
	Xecho known Julian Days
	Xecho '2446066.5  == Jan 1.0 1985 GMT: the Astronomical Ephemeris'
	Xecho "2446065.5  == 0000 hours Jan 0 1985:  Observer's Handbook 1985 pg 20"
	Xecho '2446065    == 12n GMT 12/31/84: 1985 World Almanac pg 751 (wrong)'
	Xecho 1984	 12	 31	  0	0	   0	2446066
	Xgreg 1984	 12	 31	  0	0	   0	2446066
	Xecho $?
	Xecho '2446430    == 12n GMT 12/31/85: 1986 World Almanac pg 751 (wrong)'
	Xecho 1985	 12	 31	  0	0	   0	2446430
	Xgreg 1985	 12	 31	  0	0	   0	2446430
	Xecho $?
	Xcal 3 1900 # delete this line if you don't have cal to run
	Xecho 'from Tantzen paper k=1'
	Xecho 1900	 3	 1	  0	0	   0	2415080
	Xgreg 1900	 3	 1	  0	0	   0	2415080
	Xecho $?
	Xcal 12 1999 # delete this line if you don't have cal to run
	Xecho 'from Tantzen paper k=36465'
	Xecho 1999	 12	 31	  0	0	   0	2451544
	Xgreg 1999	 12	 31	  0	0	   0	2451544
	Xecho $?
	Xecho '2440587.5 == Jan 1.0 1970 GMT: Astronomical Ephemeris'
	Xecho '2440588   == 12n 1/1/70: Fliegel paper'
	Xcal 1 1970 # delete this line if you don't have cal to run
	Xecho 1970	 1	 1	  0	0	   0	2440588
	Xgreg 1970	 1	 1	  0	0	   0	2440588
	Xecho $?
	X
	Xecho test bad parameters
	Xecho	no parameters					
	Xgreg	# empty					
	Xecho $?
	Xecho    1	 0	 0	  0	0	   0	    0	0 # too many
	Xgreg    1	 0	 0	  0	0	   0	    0	0
	Xecho $?
	Xecho   -1	 0	 0	  0	0	   0	# negative year
	Xgreg   -1	 0	 0	  0	0	   0	
	Xecho $?
	X
	Xecho 'end of tests'
SHAR_EOF
if test 6906 -ne "`wc -c < 'test.exe'`"
then
	echo shar: error transmitting "'test.exe'" '(should have been 6906 characters)'
fi
chmod +x 'test.exe'
fi # end of overwriting check
echo shar: extracting "'test.author'" '(7855 characters)'
if test -f 'test.author'
then
	echo shar: will not over-write existing file "'test.author'"
else
sed 's/^	X//' << \SHAR_EOF > 'test.author'
	X   December 1985
	X S  M Tu  W Th  F  S
	X 1  2  3  4  5  6  7
	X 8  9 10 11 12 13 14
	X15 16 17 18 19 20 21
	X22 23 24 25 26 27 28
	X29 30 31
	X
	Xsmoke test
	Xgreg 1985 12 10
	X1985 12 10 3 2 344 2446410
	X0
	Xtest input validity checking capability
	X1985 12 10 3 2 344 2446410
	X1985 12 10 3 2 344 2446410
	X0
	Xtest various input inversions
	X1985 0 0 0 0 344 0
	X1985 12 10 3 2 344 2446410
	X0
	X0 0 0 0 0 0 2446410
	X1985 12 10 3 2 344 2446410
	X0
	X1985 12 0 3 1 0
	X1985 12 3 3 1 337 2446403
	X0
	X1985 12 0 3 2 0
	X1985 12 10 3 2 344 2446410
	X0
	X1985 12 0 3 3 0
	X1985 12 17 3 3 351 2446417
	X0
	X1985 12 0 3 4 0
	X1985 12 24 3 4 358 2446424
	X0
	X1985 12 0 3 5 0
	X1985 12 31 3 5 365 2446431
	X0
	X1985 12 0 3 6 0
	Xgreg: input does not describe a valid gregorian date
	X1985 12 38 3 6 372 0
	X1
	X1985 12 0 3 7 0
	Xgreg: input does not describe a valid gregorian date
	X1985 12 45 3 7 379 0
	X1
	X1985 12 0 7 6 0
	Xgreg: input does not describe a valid gregorian date
	X1985 12 42 7 6 376 0
	X1
	X1985 11 0 1 1 0
	Xgreg: input does not describe a valid gregorian date
	X1985 11 -4 1 1 300 0
	X1
	X1985 12 10 3 0 344
	X1985 12 10 3 2 344 2446410
	X0
	X1985 12 10 0 2 0
	X1985 12 10 3 2 344 2446410
	X0
	X1985 12 10 0 3 0
	Xgreg: input does not describe a valid gregorian date
	X1985 12 10 3 3 344 2446410
	X1
	X1985 12 10 2 0 0
	Xgreg: input does not describe a valid gregorian date
	X1985 12 10 2 0 344 2446410
	X1
	X1985 12 10 0 0 344
	X1985 12 10 3 2 344 2446410
	X0
	X1985 12 0 0 0 344
	X1985 12 10 3 2 344 2446410
	X0
	X1985 0 10 0 0 344
	X1985 12 10 3 2 344 2446410
	X0
	X1985 12 10 0 0 345
	Xgreg: input does not describe a valid gregorian date
	X1985 12 10 0 0 345 0
	X1
	Xtest first of a bunch of months
	X1985 1 1 0 0 0
	X1985 1 1 3 1 1 2446067
	X0
	X1985 2 1 0 0 0
	X1985 2 1 6 1 32 2446098
	X0
	X1985 3 1 0 0 0
	X1985 3 1 6 1 60 2446126
	X0
	X1985 4 1 0 0 0
	X1985 4 1 2 1 91 2446157
	X0
	X1985 5 1 0 0 0
	X1985 5 1 4 1 121 2446187
	X0
	X1985 6 1 0 0 0
	X1985 6 1 7 1 152 2446218
	X0
	X1985 7 1 0 0 0
	X1985 7 1 2 1 182 2446248
	X0
	X1985 8 1 0 0 0
	X1985 8 1 5 1 213 2446279
	X0
	X1985 9 1 0 0 0
	X1985 9 1 1 1 244 2446310
	X0
	X1985 10 1 0 0 0
	X1985 10 1 3 1 274 2446340
	X0
	X1985 11 1 0 0 0
	X1985 11 1 6 1 305 2446371
	X0
	X1985 12 1 0 0 0
	X1985 12 1 1 1 335 2446401
	X0
	Xtest funny leap years
	X   March 2000
	X S  M Tu  W Th  F  S
	X          1  2  3  4
	X 5  6  7  8  9 10 11
	X12 13 14 15 16 17 18
	X19 20 21 22 23 24 25
	X26 27 28 29 30 31
	X
	X2000 3 1 0 0 0
	X2000 3 1 4 1 61 2451605
	X0
	X   March 1900
	X S  M Tu  W Th  F  S
	X             1  2  3
	X 4  5  6  7  8  9 10
	X11 12 13 14 15 16 17
	X18 19 20 21 22 23 24
	X25 26 27 28 29 30 31
	X
	X1900 3 1 0 0 0
	X1900 3 1 5 1 60 2415080
	X0
	Xtest first and last day
	X
	X
	X
	X				1984
	X
	X	 Jan			Feb		       Mar
	X S  M Tu  W Th  F  S    S  M Tu  W Th  F  S    S  M Tu  W Th  F  S
	X 1  2  3  4  5  6  7             1  2  3  4                1  2  3
	X 8  9 10 11 12 13 14    5  6  7  8  9 10 11    4  5  6  7  8  9 10
	X15 16 17 18 19 20 21   12 13 14 15 16 17 18   11 12 13 14 15 16 17
	X22 23 24 25 26 27 28   19 20 21 22 23 24 25   18 19 20 21 22 23 24
	X29 30 31               26 27 28 29            25 26 27 28 29 30 31
	X
	X	 Apr			May		       Jun
	X S  M Tu  W Th  F  S    S  M Tu  W Th  F  S    S  M Tu  W Th  F  S
	X 1  2  3  4  5  6  7          1  2  3  4  5                   1  2
	X 8  9 10 11 12 13 14    6  7  8  9 10 11 12    3  4  5  6  7  8  9
	X15 16 17 18 19 20 21   13 14 15 16 17 18 19   10 11 12 13 14 15 16
	X22 23 24 25 26 27 28   20 21 22 23 24 25 26   17 18 19 20 21 22 23
	X29 30                  27 28 29 30 31         24 25 26 27 28 29 30
	X
	X	 Jul			Aug		       Sep
	X S  M Tu  W Th  F  S    S  M Tu  W Th  F  S    S  M Tu  W Th  F  S
	X 1  2  3  4  5  6  7             1  2  3  4                      1
	X 8  9 10 11 12 13 14    5  6  7  8  9 10 11    2  3  4  5  6  7  8
	X15 16 17 18 19 20 21   12 13 14 15 16 17 18    9 10 11 12 13 14 15
	X22 23 24 25 26 27 28   19 20 21 22 23 24 25   16 17 18 19 20 21 22
	X29 30 31               26 27 28 29 30 31      23 24 25 26 27 28 29
	X                                              30
	X	 Oct			Nov		       Dec
	X S  M Tu  W Th  F  S    S  M Tu  W Th  F  S    S  M Tu  W Th  F  S
	X    1  2  3  4  5  6                1  2  3                      1
	X 7  8  9 10 11 12 13    4  5  6  7  8  9 10    2  3  4  5  6  7  8
	X14 15 16 17 18 19 20   11 12 13 14 15 16 17    9 10 11 12 13 14 15
	X21 22 23 24 25 26 27   18 19 20 21 22 23 24   16 17 18 19 20 21 22
	X28 29 30 31            25 26 27 28 29 30      23 24 25 26 27 28 29
	X                                              30 31
	X
	X
	X
	X1984 1 1 0 0 0
	X1984 1 1 1 1 1 2445701
	X0
	X1984 12 31 0 0 0
	X1984 12 31 2 6 366 2446066
	X0
	Xviolate various calendar limitations
	X1984 0 0 0 0 1
	X1984 1 1 1 1 1 2445701
	X0
	X1984 0 0 0 0 366
	X1984 12 31 2 6 366 2446066
	X0
	X1984 0 0 0 0 367
	Xgreg: input does not describe a valid gregorian date
	X1984 13 1 3 1 367 2446067
	X1
	X1984 13 1 0 0 0
	Xgreg: input does not describe a valid gregorian date
	X1984 13 1 3 1 367 2446067
	X1
	Xthoroughly test a February
	X1984 2 1 0 0 0
	X1984 2 1 4 1 32 2445732
	X0
	X1984 2 2 0 0 0
	X1984 2 2 5 1 33 2445733
	X0
	X1984 2 3 0 0 0
	X1984 2 3 6 1 34 2445734
	X0
	X1984 2 4 0 0 0
	X1984 2 4 7 1 35 2445735
	X0
	X1984 2 5 0 0 0
	X1984 2 5 1 2 36 2445736
	X0
	X1984 2 6 0 0 0
	X1984 2 6 2 2 37 2445737
	X0
	X1984 2 7 0 0 0
	X1984 2 7 3 2 38 2445738
	X0
	X1984 2 8 0 0 0
	X1984 2 8 4 2 39 2445739
	X0
	X1984 2 9 0 0 0
	X1984 2 9 5 2 40 2445740
	X0
	X1984 2 10 0 0 0
	X1984 2 10 6 2 41 2445741
	X0
	X1984 2 11 0 0 0
	X1984 2 11 7 2 42 2445742
	X0
	X1984 2 12 0 0 0
	X1984 2 12 1 3 43 2445743
	X0
	X1984 2 13 0 0 0
	X1984 2 13 2 3 44 2445744
	X0
	X1984 2 14 0 0 0
	X1984 2 14 3 3 45 2445745
	X0
	X1984 2 15 0 0 0
	X1984 2 15 4 3 46 2445746
	X0
	X1984 2 16 0 0 0
	X1984 2 16 5 3 47 2445747
	X0
	X1984 2 17 0 0 0
	X1984 2 17 6 3 48 2445748
	X0
	X1984 2 18 0 0 0
	X1984 2 18 7 3 49 2445749
	X0
	X1984 2 19 0 0 0
	X1984 2 19 1 4 50 2445750
	X0
	X1984 2 20 0 0 0
	X1984 2 20 2 4 51 2445751
	X0
	X1984 2 21 0 0 0
	X1984 2 21 3 4 52 2445752
	X0
	X1984 2 22 0 0 0
	X1984 2 22 4 4 53 2445753
	X0
	X1984 2 23 0 0 0
	X1984 2 23 5 4 54 2445754
	X0
	X1984 2 24 0 0 0
	X1984 2 24 6 4 55 2445755
	X0
	X1984 2 25 0 0 0
	X1984 2 25 7 4 56 2445756
	X0
	X1984 2 26 0 0 0
	X1984 2 26 1 5 57 2445757
	X0
	X1984 2 27 0 0 0
	X1984 2 27 2 5 58 2445758
	X0
	X1984 2 28 0 0 0
	X1984 2 28 3 5 59 2445759
	X0
	X1984 2 29 0 0 0
	X1984 2 29 4 5 60 2445760
	X0
	Xshould fail
	X1985 2 29 0 0 0
	Xgreg: input does not describe a valid gregorian date
	X1985 2 29 0 0 60 0
	X1
	X1984 2 30 0 0 0
	Xgreg: input does not describe a valid gregorian date
	X1984 2 30 0 0 61 0
	X1
	Xtest around March 1
	X1984 0 0 0 0 59
	X1984 2 28 3 5 59 2445759
	X0
	X1984 0 0 0 0 60
	X1984 2 29 4 5 60 2445760
	X0
	X1984 0 0 0 0 61
	X1984 3 1 5 1 61 2445761
	X0
	X1984 2 0 0 0 61
	Xgreg: input does not describe a valid gregorian date
	X1984 2 0 0 0 61 0
	X1
	Xknown Julian Days
	X2446066.5  == Jan 1.0 1985 GMT: the Astronomical Ephemeris
	X2446065.5  == 0000 hours Jan 0 1985:  Observer's Handbook 1985 pg 20
	X2446065    == 12n GMT 12/31/84: 1985 World Almanac pg 751 (wrong)
	X1984 12 31 0 0 0 2446066
	X1984 12 31 2 6 366 2446066
	X0
	X2446430    == 12n GMT 12/31/85: 1986 World Almanac pg 751 (wrong)
	X1985 12 31 0 0 0 2446430
	Xgreg: input does not describe a valid gregorian date
	X1985 12 31 0 0 364 2446430
	X1
	X   March 1900
	X S  M Tu  W Th  F  S
	X             1  2  3
	X 4  5  6  7  8  9 10
	X11 12 13 14 15 16 17
	X18 19 20 21 22 23 24
	X25 26 27 28 29 30 31
	X
	Xfrom Tantzen paper k=1
	X1900 3 1 0 0 0 2415080
	X1900 3 1 5 1 60 2415080
	X0
	X   December 1999
	X S  M Tu  W Th  F  S
	X          1  2  3  4
	X 5  6  7  8  9 10 11
	X12 13 14 15 16 17 18
	X19 20 21 22 23 24 25
	X26 27 28 29 30 31
	X
	Xfrom Tantzen paper k=36465
	X1999 12 31 0 0 0 2451544
	X1999 12 31 6 5 365 2451544
	X0
	X2440587.5 == Jan 1.0 1970 GMT: Astronomical Ephemeris
	X2440588   == 12n 1/1/70: Fliegel paper
	X   January 1970
	X S  M Tu  W Th  F  S
	X             1  2  3
	X 4  5  6  7  8  9 10
	X11 12 13 14 15 16 17
	X18 19 20 21 22 23 24
	X25 26 27 28 29 30 31
	X
	X1970 1 1 0 0 0 2440588
	X1970 1 1 5 1 1 2440588
	X0
	Xtest bad parameters
	Xno parameters
	Xgreg: insufficient information
	Xusage: greg year month day [day0week week0month day0year jd]
	X2
	X1 0 0 0 0 0 0 0
	Xgreg: input does not describe a valid gregorian date
	X0 0 0 0 0 0 0
	X1
	X-1 0 0 0 0 0
	Xgreg: input does not describe a valid gregorian date
	X-1 0 0 0 0 0 0
	X1
	Xend of tests
SHAR_EOF
if test 7855 -ne "`wc -c < 'test.author'`"
then
	echo shar: error transmitting "'test.author'" '(should have been 7855 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0
-- 
W. M. McKeeman            mckeeman@WangInst
Wang Institute            decvax!wanginst!mckeeman
Tyngsboro MA 01879

jmc@warwick.UUCP (John Collins) (01/07/86)

This doesn't work!!!!
It thinks 1952 wasn't a leap year and gets dates prior to 1st March wrong!!
Haven't had time to look at it but beware!!

John Collins