home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-12-21 | 50.0 KB | 1,454 lines |
- Newsgroups: alt.sources
- Path: sparky!uunet!spool.mu.edu!agate!linus!linus.mitre.org!truth!jrv
- From: jrv@truth.mitre.org (Van Zandt)
- Subject: julcal - Julian date functions
- Message-ID: <1992Dec21.124514.18885@linus.mitre.org>
- Followup-To: alt.sources.d
- Keywords: Julian, Gregorian, calendar, dates, struct tm
- Sender: news@linus.mitre.org (News Service)
- Nntp-Posting-Host: truth.mitre.org
- Organization: The MITRE Corp., Bedford, Ma.
- Date: Mon, 21 Dec 1992 12:45:14 GMT
- Lines: 1440
-
- Subject: julcal - Julian date functions in C
- Followup-To: alt.sources.d
-
- Archive-name: julcal
- Submitted-by: jrv@mitre.org (Jim Van Zandt)
- Version: $Id: julcal.c%v 1.10 1992/12/13 03:15:59 jrv Exp jrv $
- Keywords: Julian, Gregorian, calendar, dates, struct tm
-
- The standard C library routines for dates tend to fail before Jan 1,
- 1970. These routines let you do date calculations back to 4713 B.C.
- using an ordinary struct tm.
-
- Like mktime(), juldn() has the side effects of normalizing the values
- of the fields tm_mday and tm_mon if they are outside their normal
- ranges, and of setting the fields tm_wday (day of week) and tm_yday
- (day of year). However, mktime() is one of the functions that usually
- fails before 1970, and the implementations I tested didn't normalize
- correctly, sometimes making spectacular errors.
-
- # This is a shell archive.
- # Remove everything above and including the cut line.
- # Then run the rest of the file through sh.
- #----cut here-----cut here-----cut here-----cut here----#
- #!/bin/sh
- # shar: Shell Archiver
- # Run the following text with /bin/sh to create:
- # julcal.c
- # julcal.h
- # tjul.c
- # dates.txt
- # data
- # makefile
- # makefile.ux
- # This archive created: Sat Dec 19 15:29:40 1992
- cat << \SHAR_EOF > julcal.c
- /*
- Julian (sense 1) date routines, handling both Julian (sense 2) and
- Gregorian calendars
-
- SYNOPSIS
- long juldn (struct tm *bdt)
- long juldnj (struct tm *bdt, long Transition)
- long juldnd (struct tm *bdt, struct tm *Transition_date)
-
- struct tm *julcd (long J)
- struct tm *julcdj (long J, long Transition)
- struct tm *julcdd (long J, struct tm *Transition_date)
-
- extern long jul_transition;
-
- DESCRIPTION
-
- juldn* returns the Julian day number (days since Jan 1, 4713 B.C.)
- for the date specified by the struct tm (a broken down time)
- pointed to by 'bdt'. Only the tm_year, tm_mon, and tm_mday fields
- are examined. If the month or day fields are out of their normal
- range, they are adjusted. The tm_wday and tm_yday fields are also
- set.
-
- julcd* returns a pointer to a struct tm filled in with the date
- corresponding to the Julian day number 'J'. Five fields are set:
- tm_year, tm_mon, tm_mday, tm_wday, and tm_yday. The pointer is to
- a static structure which is reused on each call.
-
- For both juldn and julcd, the Gregorian calendar is assumed
- provided the Julian day number falls on or after the value in the
- global variable 'jul_transition', otherwise the Julian calendar is
- used. 'jul_transition' is initialized to 2361222 (or September 14,
- 1752), as in the United Kingdom and the colonies. A different
- transition can be specified by Julian day number (for juldnj or
- julcdj) or Gregorian date (for juldnd or julcdd). Alternatively,
- 'jul_transition' can be reset. If the transition is specified by
- date, ensure it is interpreted as a Gregorian date by using julcdj
- with a small number:
-
- jul_transition = julcdj(&my_transition_date, 1L);
-
- Algorithm is valid from 4713 B.C. to 19,999 A.D. For caveats,
- see below.
-
- Aside: In a struct tm, the tm_year field is "year-1900". For the
- year 1 A.D., that would be -1899. There was no year 0 (the number
- zero had not been invented!), so the previous year was 1 B.C.,
- which is represented by -1900.
-
- HISTORY
-
- $Id: julcal.c%v 1.10 1992/12/13 03:15:59 jrv Exp jrv $
-
- $Log: julcal.c%v $
- * Revision 1.10 1992/12/13 03:15:59 jrv
- * default transition date is that for the United Kingdom
- *
- * Revision 1.9 1992/12/13 03:07:07 jrv
- * juldnj gives correct value even if month is outside normal range.
- * juldnj normalizes mday, month, and year.
- * _juldnj introduced to let julcdj set yday without causing infinite recursion.
- *
- * Revision 1.8 1992/12/08 00:23:38 jrv
- * Test program moved to a separate file.
- *
- * Revision 1.7 1992/12/06 01:57:20 jrv
- * julcd* return pointers to a static struct tm, like localtime and gmtime.
- *
- * Revision 1.6 1992/12/05 23:14:58 jrv
- * The default transition date is a global variable, initialized to 15 Oct 1582.
- * Some variable names changed. All variables are lower case.
- *
- * Revision 1.5 1992/12/05 22:20:11 jrv
- * juldnd accepts a struct tm (a "broken-down time") instead of a
- * unique struct. julcdd produces a struct tm (including tm_wday
- * and tm_yday fields) instead of a unique struct.
- *
- * Revision 1.4 1992/12/05 20:04:51 jrv
- * Test program prints input values, then computed values.
- * Test program is silent by default.
- *
- * Revision 1.3 1992/12/04 02:57:54 jrv
- * Reformatted to more standard C.
- * Eliminated some redundant typedefs.
- * Type Year is now an int rather than a long.
- * Some variables converted to lower case.
- *
- * Revision 1.2 1992/12/04 02:15:58 jrv
- * A Year is no longer unsigned, so years BC work.
- * Regression test driver added.
- *
- * Revision 1.1 1992/12/04 00:21:37 jrv
- * Initial revision
- *
-
- Translated from Pascal to C by Jim Van Zandt, July 1992.
-
- Error-free translation based on error-free PL/I source
-
- Based on Pascal code copyright 1985 by Michael A. Covington,
- published in P.C. Tech Journal, December 1985, based on formulae
- appearing in Astronomical Formulae for Calculators by Jean Meeus
-
- Reconversion to normal Julian epoch, integer arithmetic and
- 4000-year correction by John W. Kennedy
-
- [The 4000-year adjustment is controversial. It is not mentioned in
- the paper "Calendrical Calculations" by Nachum Dershowitz and
- Edward M. Reingold in Software Practice and Experience, v 20 n 9
- pp 899-928 (Sep 1990). I have left it in mainly because it will
- make no difference for a very long time. - jvz]
-
- Historical exceptions _not_ allowed for in this package:
-
- Until Julius Caesar established the Julian calendar in 45 B.C.,
- calendars were irregular. This package assumes the Julian calendar
- back to 4713 B.C.
-
- The Julian calendar was altered in 8 B.C. From 45 B.C. to 8 B.C.,
- the months were
- Jan=31, Feb=29(30), Mar=31, Apr=30, May=31, Jun=30,
- Jul=31, Aug=30, Sep=31, Oct=30, Nov=31, Dec=30
- This package assumes the month lengths as we know them.
-
- Leap years from 45 B.C. to 8 A.D. were miscalculated: (45, 42,
- 39, 36, 33, 30, 27, 24, 21, 18, 15, 12, 9, then none at all until 8
- A.D.) This package assumes leap years every four years, as they
- were meant to have been.
-
- January 1 was not always the first day of the year. The United
- Kingdom, in particular, started the year on March 25 until 1752.
- (However, the year ended on December 31, leaving the days between
- in limbo.) This package assumes January 1 is the first day of the
- year.
-
- Leap-year day was originally done by having February 24 (25 from 45
- to 8 B.C.) twice. This package assumes Leap-year day is February
- 29.
-
- "Transition" argument is the first Julian date to be considered as
- belonging to the Gregorian calendar. Usual values are:
-
- 2299161 = October 5/15, 1582, as in Rome, or
- 2361222 = September 3/14, 1752, as in the United Kingdom
- and the Colonies
-
- For more on the history of calendars, including transition dates in
- other countries, see Bob Douglas' article in dates.txt.
-
- */
-
- #include <time.h>
- #include "julcal.h"
-
- typedef long Julian;
- typedef int Year;
- typedef int Month;
- typedef int Day;
-
- Julian jul_transition=JUL_ENGLAND;
-
- /*
- Julian juldnj (struct tm *bdt, Julian Transition);
- Julian juldn (struct tm *bdt);
- Julian juldnd (struct tm *bdt, struct tm *Transition_date);
-
- struct tm *julcdj (Julian J, Julian Transition);
- struct tm *julcd (Julian J);
- struct tm *julcdd (Julian J, struct tm *Transition_date);
- */
-
- typedef long Work;
-
- static Julian
- _juldnj(bdt, Transition) struct tm *bdt; Julian Transition;
- {
- Year ay, y, dy;
- Month m;
- Julian jd_julian, jd_gregorian, jd;
-
- y = bdt->tm_year + 1900;
- m = bdt->tm_mon;
-
- dy = m/12;
- y += dy;
- m -= dy*12;
- /* assert( -11 <= m && m <= 11 ) */
- if(m < 0)
- {
- m += 12;
- y--;
- }
- /* assert( 0 <= m && m <= 11 ) */
-
- if ( m < 2 )
- {
- m += 1 + 12;
- y--;
- }
- else
- m++;
-
- ay = y + 4716;
- jd_julian = ((1461*(Work)ay) >> 2) + (153*(m + 1)/5)
- + (Work)bdt->tm_mday - 1524;
- jd_gregorian = jd_julian + 2 - y/100 + y/400 - y/4000;
- if ( jd_gregorian >= Transition ) jd = jd_gregorian;
- else jd = jd_julian;
- return jd;
- }
-
- /* this wrapper can call julcdj without causing infinite recursion */
- Julian
- juldnj(bdt, Transition) struct tm *bdt; Julian Transition;
- { Julian jd;
- struct tm *normal;
-
- jd = _juldnj(bdt, Transition);
-
- normal = julcdj(jd, Transition);
- bdt->tm_year = normal->tm_year;
- bdt->tm_mon = normal->tm_mon;
- bdt->tm_mday = normal->tm_mday;
- bdt->tm_wday = normal->tm_wday;
- bdt->tm_yday = normal->tm_yday;
-
- return jd;
- }
-
- Julian
- juldn (bdt) struct tm *bdt;
- { return juldnj (bdt, jul_transition);
- }
-
- Julian
- juldnd (bdt, Transition_date) struct tm *bdt; struct tm *Transition_date;
- { return juldnj (bdt, _juldnj (Transition_date, 1L));
- }
-
- struct tm *
- julcdj (jd, Transition) Julian jd; Julian Transition;
- {
- Julian aa, ab, a;
- Work b, d, ee;
- Year ay;
- Month em, m;
- Year y;
- struct tm newyears;
- static struct tm date;
-
- memset(&date, 0, sizeof(date));
-
- if ( jd < Transition ) /* Julian Calendar */
- a = (Work)(jd);
- else /* Gregorian Calendar */
- {
- aa = jd - 1721120L;
- ab = 31*(aa/1460969L); aa = aa % 1460969L;
- ab = ab + 3*(aa/146097L); aa = aa % 146097L;
- if ( aa == 146096L ) ab = ab + 3;
- else ab = ab + aa/36524L;
- a = jd + (ab - 2);
- }
- b = a + 1524;
- ay = (Year)((20*b - 2442)/7305);
- d = (1461*(Work)(ay)) >> 2;
- ee = b - d;
- em = (Month)(10000L*ee/306001L);
-
- date.tm_mday = (Day)(ee - 306001L*em/10000L);
-
- m = em - 1;
- if(m > 12) m -= 12;
- date.tm_mon = m - 1;
-
- if ( m > 2 ) y = ay - 4716;
- else y = ay - 4715;
- date.tm_year = y - 1900;
-
- date.tm_wday = (jd+1)%7;
-
- newyears = date;
- newyears.tm_mon = 0;
- newyears.tm_mday = 1;
- date.tm_yday = jd - _juldnj(&newyears, Transition);
- return &date;
- }
-
- struct tm *
- julcd(jd) Julian jd;
- { return julcdj (jd, jul_transition);
- }
-
- struct tm *
- julcdd(jd, Transition_date) Julian jd; struct tm *Transition_date;
- { return julcdj (jd, _juldnj (Transition_date, 1L));
- }
- SHAR_EOF
- cat << \SHAR_EOF > julcal.h
- /*
- declarations for Julian date routines
- */
-
- #define JUL_ROME 2299161L
- #define JUL_ENGLAND 2361222L
-
- extern long jul_transition;
-
- #ifdef __STDC__
-
- long juldnj (struct tm *bdt, long Transition);
- long juldn (struct tm *bdt);
- long juldnd (struct tm *bdt, struct tm *Transition_date);
-
- struct tm *julcdj (long JD, long Transition);
- struct tm *julcd (long JD);
- struct tm *julcdd (long JD, struct tm *Transition_date);
-
- #else
-
- long juldnj ();
- long juldn ();
- long juldnd ();
-
- struct tm *julcdj ();
- struct tm *julcd ();
- struct tm *julcdd ();
-
- #endif
- SHAR_EOF
- cat << \SHAR_EOF > tjul.c
- #define MKTIME
- /*
- NAME
- tjul - test julcal family of Julian day number programs
-
- SYNOPSIS
- julcal [-v] [datafile]
-
- NOTES
- Default datafile name is "data". Nothing is printed unless an
- error is found.
-
- OPTIONS
- -v verbose: print all comment lines, input data, calculated dates,
- first 10 lines of each set of random tests
-
- INPUT
- A ';' introduces a comment.
-
- If the first character is 'T', it is followed by the Julian
- date for transition to the Gregorian calendar. (Initially, the
- transition date is JD2361222 = September 14, 1752, as in England.)
-
- Otherwise, each line has six items:
- julian_day year month mday wday yday
- 2299159 1582 10 3 Wed 275
- where
- julian_day is the number of days since Jan 1, 4713 B.C.
- year is negative for B.C.
- month is in the range [1...12]
- mday is in the range [1...31]
- yday is in the range [0...365]
-
- OUTPUT
- In case of error...
-
- The input data.
- The Julian day calculated from the date by juldn.
- The year, month, day, weekday, and day of year (0...365)
- calculated from the Julian day by julcd.
-
- Outputs that don't match the corresponding inputs are marked with '*'.
-
- JD date juldn(date) julcd(JD)
- ------- ------------------ ----------- --------------------
- 2430336 1941 12 7 Sun 340 2430336 1941 12 7 Sun 340
-
- There are also three sets of random tests. Again, '*'
- indicates a disagreement.
-
- The first set is for self consistency: two dates, ten days
- apart, should result in Julian dates that differ by ten.
-
- The second set compares the normalization of dates as found by
- mktime and juldn. Due to buggy implementations of mktime
- (Borland, Sun), in case of a disagreement the test program
- tries to identify which function is incorrect. First, it
- adjusts the month and compensates with the year. If the two
- functions then agree, it prints their results. Otherwise, it
- looks for a boundary between agreement and disagreement. It
- then prints results for dates on each side of the boundary. In
- either case, comparing the last two lines should show which
- function is incorrect.
-
- The third set compares tm_wday and tm_yday as found by julcd(),
- juldn(), and gmtime().
-
- */
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- #include "julcal.h"
-
- #define BUFSIZE 200
-
- char buf[BUFSIZE+1];
- FILE *ifile;
- char *filename = "data";
- #define streq(a,b) (strcmp(a,b)==0)
-
- main(argc, argv) int argc; char **argv;
- { char *s, tdayname[4];
- static char *weekdayname[] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
- static char item1_heading[]=
- " JD date juldn(date) julcd(JD)\n\
- ------- ------------------ ----------- --------------------\n";
- static char item2_heading[]=
- "\n\
- before after\n\
- -------------- --------------------------\n\
- year month day year month day Julian day\n";
- #ifdef MKTIME
- static char item3_heading[]=
- "\n\
- before mktime juldn\n\
- -------------- -------------- --------------\n";
- int item3=0;
- #endif
- static char item4_heading[]=
- "\n\
- gmtime julcd juldn\n\
- ---------------------- ---------- ----------\n\
- time_t date wday yday wday yday wday yday\n";
- /* xxxxxxxxxx -> 4444/22/22 -> 1 333 1 333 */
- int item4=0;
-
- int fields, same_jd, same_date, i;
- int verbose=0, item1=0, item2=0;
- long tjd; struct tm tbdt; /* test data, from file */
- long rjd; struct tm rbdt; /* results, from functions */
- long j0, j10;
- int tyear, ryear, dy, dd, error;
- time_t when;
- struct tm *bdt1, *bdt2;
- struct tm before, before0, before10, after0, after10, theirs, ours;
-
- for (i = 1; i < argc; i++)
- {if(streq(argv[i],"-v")) verbose=1;
- else filename = argv[i];
- }
-
- ifile = fopen(filename, "r");
- if(ifile == 0) {fprintf(stderr, "can't open file %s\n", filename); exit(1);}
-
- while(fgets(buf, BUFSIZE, ifile))
- {
- if(s = strchr(buf, '\n')) *s = 0; /* zap LF */
- if(buf[0] == ';')
- {
- if(verbose) printf("%s\n", buf); /* echo cmt line */
- continue;
- }
- if(buf[0] == 'T')
- { /* set new default transition date */
- sscanf(buf, "T%ld", &jul_transition);
- if(verbose) printf("%s\n", buf);
- continue;
- }
- if(s = strchr(buf, ';')) *s = 0; /* zap trailing comment */
- tbdt.tm_year = 0;
- tbdt.tm_mon = 0;
- tbdt.tm_mday = 1;
- tbdt.tm_wday = 1;
- fields = sscanf(buf, "%ld %d %d %d %3s %d", &tjd, &tbdt.tm_year,
- &tbdt.tm_mon, &tbdt.tm_mday, &tdayname, &tbdt.tm_yday);
- if(fields < 1) continue;
- for (i = 0; i < 7; i++)
- if(streq(tdayname, weekdayname[i]))
- break;
- tbdt.tm_wday = i;
-
- /* adjust for struct_tm offsets */
- if(tbdt.tm_year < 0) tbdt.tm_year -= 1899;
- else tbdt.tm_year -= 1900;
- tbdt.tm_mon--;
-
- rjd = juldn(&tbdt);
- rbdt = *julcd(tjd);
-
- same_date = (rbdt.tm_year == tbdt.tm_year)
- && (rbdt.tm_mon == tbdt.tm_mon)
- && (rbdt.tm_mday == tbdt.tm_mday)
- && (rbdt.tm_wday == tbdt.tm_wday)
- && (rbdt.tm_yday == tbdt.tm_yday);
- same_jd = (rjd == tjd);
- if(verbose || !same_jd || !same_date)
- {
- if(!item1) printf(item1_heading);
- item1 = 1;
- tyear = tbdt.tm_year + 1900; if(tyear < 1) tyear--;
- ryear = rbdt.tm_year + 1900; if(ryear < 1) ryear--;
- printf("%8ld %5d %2d %2d %3s %3d %7ld %s %5d %2d %2d %s %3d %s\n",
- tjd, tyear, tbdt.tm_mon+1, tbdt.tm_mday, tdayname, tbdt.tm_yday,
- rjd, same_jd?" ":"*",
- ryear, rbdt.tm_mon+1, rbdt.tm_mday,
- weekdayname[rbdt.tm_wday], rbdt.tm_yday,
- same_date?" ":"*");
- }
- }
-
- /*
- Check normalization (correction for day or month out of the normal
- range) of juldnj.
-
- */
- for (i = 0; i < 5000; i++)
- { /* test period is 1780 - 5 - 1 ... 1780 + 700 + 5 + 1
- or 1774 ... 2486
- (after transition to Gregorian calendar) */
- before0.tm_year = 1780 - 1900 + rand()%700;
- before0.tm_mon = -60 + rand()%120;
- before0.tm_mday = -360 + rand()%720;
- before0.tm_sec = before0.tm_min = before0.tm_hour = 0;
- before10 = before0;
- dy = rand()%14;
- before10.tm_year -= dy;
- before10.tm_mon += dy*12;
- before10.tm_mday += 10;
- /* 'before10' now has a date 10 days later than 'before0' */
-
- after0 = before0;
- after10 = before10;
- j0 = juldn(&after0);
- j10 = juldn(&after10);
-
- /* check that final dates are normalized & 10 days apart */
- error = j10 != j0 + 10
- || after0.tm_mon < 0
- || after0.tm_mon > 11
- || after0.tm_mday < 1
- || after0.tm_mday > 31
- || after10.tm_mon < 0
- || after10.tm_mon > 11
- || after10.tm_mday < 1
- || after10.tm_mday > 31
- || ((after0.tm_mon == after10.tm_mon)?
- (after10.tm_mday != after0.tm_mday + 10)
- : ((after0.tm_mon + 1)%12 != after10.tm_mon
- || after0.tm_mday - after10.tm_mday + 10 > 31
- || after0.tm_mday - after10.tm_mday + 10 < 28));
- if((verbose && i < 10) || error)
- {
- if(!item2) printf(item2_heading);
- printf("%4d %4d %4d -> %4d %4d %4d = JD%ld\n",
- before0.tm_year+1900, before0.tm_mon+1, before0.tm_mday,
- after0.tm_year+1900, after0.tm_mon+1, after0.tm_mday, j0);
- printf("%4d %4d %4d -> %4d %4d %4d = JD%ld\n\n",
- before10.tm_year+1900, before10.tm_mon+1, before10.tm_mday,
- after10.tm_year+1900, after10.tm_mon+1, after10.tm_mday, j10);
- if(++item2 > 15) break;
- }
- }
-
- #ifdef MKTIME
- /*
- Compare normalization (correction for day or month out of the
- normal range) of juldnj with mktime().
-
- */
- for (i = 0; i < 5000; i++)
- {
- before.tm_year = 1980 - 1900 + rand()%30;
- before.tm_mon = -60 + rand()%120;
- before.tm_mday = -200 + rand()%400;
- before.tm_sec = before.tm_min = 0;
- before.tm_hour = 0;
- error = make_comparison(&before, &theirs, &ours);
- if((verbose && i < 10) || error)
- {
- if(!item3) printf(item3_heading);
- print_comparison(&before, &theirs, &ours, error);
- if(error)
- {
- dy = before.tm_mon/12;
- if(before.tm_mon < 0) dy--;
- before.tm_mon -= dy*12;
- before.tm_year += dy;
- error = make_comparison(&before, &theirs, &ours);
- if(!error) print_comparison(&before, &theirs, &ours, error);
- else
- {
- dd = before.tm_mday>0 ? 1 : -1;
- for (i = 0; i < 250; i++)
- {
- before.tm_mday -= dd;
- error = make_comparison(&before, &theirs, &ours);
- if(!error)
- {
- before.tm_mday += dd;
- error = make_comparison(&before, &theirs, &ours);
- print_comparison(&before, &theirs, &ours, error);
- before.tm_mday -= dd;
- break;
- }
- }
- error = make_comparison(&before, &theirs, &ours);
- print_comparison(&before, &theirs, &ours, error);
- }
- printf("\n");
- }
- if(++item3 > 15) break;
- }
- }
- #endif /* MKTIME */
-
- /*
- Compare calculation of tm_wday and tm_yday with gmtime(). (All these
- are after 1 Jan 1970, so necessarily A.D. and for Gregorian calendar.)
- */
- for (i = 0; i < 5000; i++) /* this takes ~5 sec on a 25 MHz 386 */
- {
- when = (((long)rand())<<16) + rand();
- bdt1 = gmtime(&when);
- ours = *bdt1;
- bdt2 = julcd(juldn(&ours)); /* both ours and *bdt2 get wday and yday */
- error = bdt1->tm_wday != bdt2->tm_wday
- || bdt1->tm_yday != bdt2->tm_yday
- || bdt1->tm_wday != ours.tm_wday
- || bdt1->tm_yday != ours.tm_yday;
- if((verbose && i < 10) || error)
- {
- if(!item4) printf(item4_heading);
- printf("%11ld -> %4d/%02d/%02d %d %3d %d %3d",
- when,
- bdt1->tm_year+1900, bdt1->tm_mon+1, bdt1->tm_mday,
- bdt1->tm_wday, bdt1->tm_yday,
- bdt2->tm_wday, bdt2->tm_yday);
- printf(" %d %3d %s\n",
- ours.tm_wday, ours.tm_yday,
- error?"*":" ");
- if(++item4 > 15) break;
- }
- }
- }
-
- make_comparison(before, theirs, ours)
- struct tm *before, *theirs, *ours;
- { *ours = *theirs = *before;
- juldn(ours);
- mktime(theirs);
- return ours->tm_year != theirs->tm_year
- || ours->tm_mon != theirs->tm_mon
- || ours->tm_mday != theirs->tm_mday;
- }
-
- print_comparison(before, theirs, ours, error)
- struct tm *before, *theirs, *ours; int error;
- {
- printf("%4d %4d %4d -> %4d %4d %4d %4d %4d %4d %s\n",
- before->tm_year+1900, before->tm_mon+1, before->tm_mday,
- theirs->tm_year+1900, theirs->tm_mon+1, theirs->tm_mday,
- ours->tm_year+1900, ours->tm_mon+1, ours->tm_mday,
- error?"*":" ");
- }
- SHAR_EOF
- cat << \SHAR_EOF > dates.txt
-
- Article 58087 (1228 more) in comp.lang.c:
-
- Subject: Re: algorithm for day-of-week
- From: comjohn@ccu1.aukuni.ac.nz (Mr. John T Jensen)
- Date: Tue, 20 Oct 1992 02:33:01 GMT
- Distribution: comp
-
- There is a very nice article with algorithms for this and other calendrical
- problems that I can recommend:
-
- Calendrical Calculations, by Nachum Dershowitz and Edward M. Reingold. In
- Software-Practice and Experience, Vol. 20, number 9 (September 1990), pp
- 899-928.
-
- jj
-
- John Thayer Jensen 64 9 373 7599 ext. 7543
- Commerce Computer Services 64 9 373 7437 (FAX)
- Auckland University jt.jensen@aukuni.ac.nz
- Private Bag 92019
- AUCKLAND
- New Zealand
-
-
-
-
-
- Article 58154 (1197 more) in comp.lang.c:
- From: msb@sq.sq.com (Mark Brader)
-
- Subject: Re: ******* DATES *********
- Date: Wed, 21 Oct 92 07:00:56 GMT
-
- > This is probably in the FAQ, but I'm feeling a rebel today.
-
- No, it isn't, but do you know, I think it should be. It certainly is
- not a C question, but it *does* seem to be Frequently Asked in this
- newsgroup anyway!
-
- > What was the final word in the leap year arguments?
-
- The final word is irrelevant, since article sequence is random and every
- post on the topic attracts a slew of fresh responses from people anxious
- to display their ignorance on a worldwide network. Now, if you want the
- *correct* answer...
-
- > Is 2000 a leap year?
-
- Yes.
-
- > Is it a single or double-exception year?
-
- Well, I'd call it a triple exception. Depends on how you count.
- Year y is a leap year if and only if:
-
- (y % 4 == 0 && y % 100 != 0) || y % 400 == 0
-
- (The parentheses are redundant, of course, but included for clarity.)
-
- Since some people seem to have trouble believing that this is right,
- here's some supporting evidence, taken from the reference book most
- conveniently to hand, the 1989 Information Please Almanac (p549-550):
-
- # For long-range accuracy, a formula suggested by the Vatican
- # librarian Aloysius Giglio (Latinized into Lilius) was adopted:
- # every fourth year is a leap year UNLESS it is a century year
- # like 1700 or 1800. Century years can be leap years ONLY when
- # they are divisible by 400 (e.g. 1600). This rule eliminates
- # three leap years in four centuries, making the calendar suf-
- # ficiently correct for all ordinary purposes.
- #
- # ... The average year of the Gregorian calendar [i.e. the one
- # just described], in spite of the leap year rule, is about 26
- # seconds longer than the earth's orbital period. But this
- # discrepancy will need 3,323 years to build up to a single day.
- #
- # Modern proposals for calendar reform do not aim at a "better"
- # calendar, but at one that is more convenient to use, especially
- # for commercial purposes. ...
-
- I also have online a copy of the British law of 1751 decreeing
- the adoption (the following year) of the Gregorian calendar
- "in and throughout all his Majesty's Dominions and Countries
- in Europe, Asia, Africa and America, belonging or subject to
- the Crown of Great Britain"; and it specifies the same rule.
- (I'll email this text to anyone who asks, but be warned that
- it's several pages long and entirely in language like that.)
- And yes, it specifies the same rule.
-
- According to past postings in sci.astro, which is probably the
- best group for this topic, a small minority of references claim
- that there is one more level of exception which has been adopted;
- but posters who would be in a position to know about this have
- said that it was wrong. It would not make sense anyway, because
- the length of the year is not sufficiently constant over millenia.
-
- > Is there a reliable, simple function around to calculate this?
- > I cannot use C, I'm building something in a 4GL and I have to
- > count days back to, well, a long time ago.
-
- Well, if it's a *long* time ago, you may get into issues of when the
- country in question *changed* to the Gregorian calendar. That could
- be anywhere from the 16th to the 20th century. Then there is the
- matter of the year not always having begun on January 1...
-
- > "This must be Thursday. I never could get the hang of Thursdays"
-
- Nice choice of quote.
- --
- Mark Brader, Toronto "If the standard says that [things] depend on the
- utzoo!sq!msb phase of the moon, the programmer should be prepared
- msb@sq.com to look out the window as necessary." -- Chris Torek
-
- This article is in the public domain.
-
-
- Article 58195 (1195 more) in comp.lang.c:
- From: bob@black.ox.ac.uk (Bob Douglas)
-
- Subject: Re: ******* DATES *********
- Date: 21 Oct 92 18:34:43 GMT
- Originator: bob@black
-
- In article <exuptr.772.719596858@exu.ericsson.se> exuptr@exu.ericsson.se (Patric
- k Taylor) writes:
-
- >This is probably in the FAQ, but I'm feeling a rebel today.
- >
- >What was the final word in the leap year arguments? Is 2000 a leap year?
- >Is it a single or double-exception year?
- >
- >Is there a reliable, simple function around to calculate this? I cannot use
- >C, I'm building something in a 4GL and I have to count days back to, well,
- >a long time ago.
-
- If you don't want to go back too far (say not before 1800) you can use
- just the Gregorian calendar whose rules are simple:
-
- A year
-
- - is a leap year if it is divisible by 400; otherwise
-
- - it is not a leap year if it is divisible by 100; otherwise
-
- - it is a leap year if it is divisible by 4; otherwise
-
- - it is not a leap year
-
- As a C statement we have
-
- leap = (year % 400 == 0) ||
- (year % 100 != 0 && year % 4 == 0)
-
- However, if you want to go back much further than 1800, you may have to
- use the Julian calendar, when things can get more complicated:
-
- - there are two formulae to consider (Julian and Gregorian)
-
- - you have to fix a date at which to start the Gregorian calendar.
- With historical dates this can depend on where dates for
- consideration arise
-
- - you may have to make adjustments to historical dates for
- places and years which do not start on 1 January
-
- If this is the case, read the material below. And good luck.
-
- Bob Douglas
-
- ===========================================================================
-
- Julian/Gregorian Calendar Changeover
- ====================================
-
- The Julian calendar was devised at the instigation of Julius Caesar and
- come into use in 45 BC or 709 AUC although confusion reigned during its
- first fifty or so years. It finally stabilized in 8 AD or 761 AUC. The
- Julian calendar has just one rule
-
- (1) Every fourth year is a leap year. The first leap year was
- 45 BC, so 1 BC was a leap year and hence so was 4 AD (there
- being no year zero: 1 BC is followed by 1 AD). Hence for years
- AD, if the year is divisible by 4, it is a leap year
-
- Thus the Julian calendar assumes a year of exactly 365.25 days.
-
- In fact the mean tropical year (used for fixing the seasons) is 365.242199
- days, which means that the Julian year is about 11 minutes 14 seconds too
- long, an error which grows to about a day in 133 years. Thus in 400 Julian
- years there are about 3 days too many.
-
- Hence in the sixteenth century Pope Gregory XIII authorized a revision of
- the calendar, and decreed that
-
- (1) Centennial years should in future no longer be leap years
- unless they were divisible by 400 (i.e. 1600, 2000, 2400
- are leap years; 1700, 1800, 1900 are not). Non-centennial
- years should continue to be leap years if they are
- divisible by 4.
-
- (2) Thursday 4 October 1582 (Julian calendar) would be followed
- by Friday 15 October 1582 (Gregorian calendar). The gap of
- 10 days corrected the accumulated error in the Julian
- calendar.
-
- Thus the Gregorian calendar assumes a year of exactly 365.2425 days,
- so it is about 26 seconds too long. This error will grow to a day in
- about 3300 years, so we can safely leave future calendar corrections
- to a (far) future generation.
-
- Note: AUC - Ab urbe condita
- From the (traditional) founding of the city (of Rome) - 753 BC
-
- ==========================================================================
-
- The above rules should make the decision about a year being a leap year
- an easy one:
-
- Using the Gregorian calendar, a year (1 AD or later):
-
- - is a leap year if it is divisible by 400; otherwise
-
- - it is not a leap year if it is divisible by 100; otherwise
-
- - it is a leap year if it is divisible by 4; otherwise
-
- - it is not a leap year
-
- Using the Julian calendar:
-
- - a positive year (AD) is a leap year if it is divisible by 4
-
- - a negative year (BC) is a leap year if its absolute value
- less 1 is divisible by 4
-
- As C statements we have
-
- Gregorian: leap = (year % 400 == 0) ||
- (year % 100 != 0 && year % 4 == 0)
-
- Julian: leap = (year > 0 ? year % 4 == 0 : (-year-1) % 4 == 0)
-
- ==========================================================================
-
- However, we are still not quite home and dry. To add to the confusion,
- the first day of the year has varied through the ages.
-
- In early Rome March was the first month of the year (hence SEPTember,
- OCTober, NOVember, DECember - months 7, 8, 9, 10); but in 153 BC,
- when consuls started entering office on 1 January, this became the
- first day of the official year.
-
- In Western Europe, in the Christian era, 1 January was gradually
- adopted as the first day of the year, but different places did
- this at widely different dates, and before this standardization
- there were several different starts to the year. For example
-
- (1) Italy, down to the 18-th century
-
- The Venetian new year started on the following 1 March
- The Pisan new year started on the preceding 25 March
- The Florentine new year started on the following 25 March
- In Rome various new years were used for different purposes
-
- (2) In England during the 14-th century the new year gradually
- changed from the preceding 25 December to the following
- 25 March. Then, by the Act that established the Gregorian
- calendar, from 1753 the new year started on 1 January
-
- (3) Scotland (independent from England until the Act of Union
- in 1707) established 1 January as the first day of the year
- from 1600.
-
- It is safe, I think, to asusme that all Gregorian calendar years start
- on 1 January.
-
- However, the effect of years that do not start on 1 January can be to
- upset the calculation of a (Julian) leap year. For example, if years
- start on the following 25 March (as for a long time they did in England),
- then the day before 1 March 1664 is 29 February 1663 (what we should call
- 29 February 1664). Thus the year which started on 1 March 1663 is a leap
- year although 1663 is not divisible by 4.
-
- This problem can be avoided by regarding years as starting always on
- 1 January, of course, but when dealing with historical dates the
- conversion to a 1 January year start depends on knowledge of the year
- start locally in use at that date:
-
- With a Pisan year 1 June 1588 becomes 1 June 1587
- With a Florentine year 1 June 1588 stays 1 June 1588
-
- With a Pisan year 1 February 1588 stays 1 February 1588
- With a Florentine year 1 February 1588 becomes 1 February 1589
-
- ==========================================================================
-
- By and large, Catholic countries adopted the Gregorian calendar at or
- about the time Gregory's edict stated. Protestant countries didn't;
- but sooner or later they had to conform as their calendars were getting
- more and more out of step with the seasons as the centuries passed.
-
- Below are (sometimes approximate) dates of calendar conversion for
- many countries. Surprisingly, there seems to be considerable doubt
- over when some areas changed. Information below is taken from
-
- Explanatory Supplement to the Astronomical Ephemeris
- and the American Ephemeris and Nautical Almanac
-
- Her Majesty's Stationary Office, London, 1961
-
- This gives several other references, mainly obscure German works.
-
- Where it is known exactly, the changeover is given in the form
-
- last Julian date - first Gregorian date
-
- otherwise approximate dates (usually just years) are given.
-
- [I have added the Julian Day Number in square brackets for the first
- Gregorian date, assuming Jan 1 where only the year is given
- - Jim Van Zandt<jrv@mitre.org>]
-
- Remember that many European countries had very different borders at the
- time of the changeover to those they have now (e.g. Poland, Hungary).
- There have been changes in political authority too. The German states
- particularly formed just a linguistic area comprising (roughly) modern
- Austria, Germany, Czechoslovakia and Switzerland; and different political
- entities (and sometimes even the ecclesiastical and civil authorities in
- one area) adopted the Gregorian calendar at different dates. See the
- above reference for more details.
-
- ==========================================================================
-
- Alaska Gregorian calendar adopted when the USA
- bought Alaska from Russia (18 October 1867)
-
- Albania December 1912
-
- American Colonies See Great Britain
-
- Austria Different regions on different dates
- 6 Oct 1583 - 16 Oct 1583 [JD2299527]
- 15 Dec 1583 - 25 Dec 1583 [JD2299597]
-
- Belgium Different authorities say
- 15 Dec 1582 - 25 Dec 1582 [JD2299232]
- 22 Dec 1582 - 1 Jan 1583 [JD2299239]
-
- Bulgaria Different authorities say
- Sometime in 1912 [JD2419403]
- 19 Mar 1916 - 1 Apr 1916 [JD2420955]
-
- China Different authorities say
- 19 Dec 1911 - 1 Jan 1912 [JD2419403]
- 19 Dec 1928 - 1 Jan 1929 [JD2425613]
-
- Czechoslovakia (i.e. Bohemia and Moravia)
- 7 Jan 1584 - 17 Jan 1584 [JD2299620]
-
- Denmark (including Norway) 19 Feb 1700 - 1 Mar 1700 [JD2342032]
-
- Egypt 1875 [JD2405890]
-
- Estonia January 1918 [JD2421595]
-
- Finland Then part of Sweden (q.v.)
-
- France 10 Dec 1582 - 20 Dec 1582 [JD2299227]
-
- German States Different states on different dates:
- 14 Feb 1583 - 24 Feb 1583 [JD2299293]
- 5 Oct 1583 - 15 Oct 1583 [JD2299526]
- 6 Oct 1583 - 16 Oct 1583 [JD2299527]
- 3 Nov 1583 - 13 Nov 1583 [JD2299555]
- 4 Nov 1583 - 14 Nov 1583 [JD2299556]
- 5 Nov 1583 - 15 Nov 1583 [JD2299557]
- 12 Nov 1583 - 22 Nov 1583 [JD2299564]
- 17 Nov 1583 - 27 Nov 1583 [JD2299569]
- 7 Jan 1584 - 17 Jan 1584 [JD2299620]
- 13 Jan 1584 - 23 Jan 1584 [JD2299626]
- 2 Jul 1584 - 12 Jul 1584 [JD2299797]
- 17 Jun 1585 - 27 Jun 1585 [JD2300147]
- 23 Aug 1610 - 2 Sep 1610 (a) [JD2309345]
- 14 Dec 1615 - 24 Dec 1615 [JD2311284]
- 16 Mar 1631 - 26 Mar 1631 [JD2316855]
- 19 Feb 1700 - 1 Mar 1700 (b) [JD2342032]
- Note:
- (a) Prussia
- (b) Protestant Germany
-
- Great Britain and Dominions 3 Sep 1752 - 14 Sep 1752 [JD2361222]
-
- Greece 10 Mar 1924 - 23 Mar 1924 [JD2423868]
-
- Hungary 22 Oct 1587 - 1 Nov 1587 [JD2301004]
-
- Italy 5 Oct 1582 - 15 Oct 1582 [JD2299161]
-
- Japan 19 Dec 1918 - 1 Jan 1919 [JD2421960]
-
- Latvia During German occupation 1915 to 1918 [1/1/1915->JD2420499]
-
- Lithuania 1915 [JD2420499]
-
- Luxemburg 15 Dec 1582 - 25 Dec 1582 [JD2299232]
-
- Netherlands Catholic: various 1582 or 1583 [10/15/1582->JD2299161]
- Protestant: various 1700 or 1701 [1/1/1700->JD2341973]
-
- Norway Then under Danish rule. See Denmark
-
- Poland 5 Oct 1582 - 15 Oct 1582 [JD2299161]
-
- Portugal 5 Oct 1582 - 15 Oct 1582 [JD2299161]
-
- Romania 1 Apr 1919 - 14 Apr 1919 [JD2422063]
-
- Spain 5 Oct 1582 - 15 Oct 1882 [JD2408734]
-
- Sweden (including Finland) 18 Feb 1753 - 1 Mar 1753 [JD2361390]
-
- Switzerland Varied with the Cantons. Generally one of
- 12 Jan 1584 - 22 Jan 1584 [JD2299625]
- 1 Jan 1701 - 12 Jan 1701 [JD2342349]
-
- Turkey 19 Dec 1926 - 1 Jan 1927 [JD2424882]
-
- Yugoslavia (as it then was) 1919 [JD2421960]
-
- UK See Great Britain
-
- USA (then American colonies) See Great Britain
-
- USSR (as it then was) 1 Feb 1918 - 14 Feb 1918 [JD2421639]
- --
- Bob Douglas Computing Services, University of Oxford
- Internet: bob@oxford.ac.uk
- Address: 13 Banbury Road, Oxford OX2 6NN, UK
- Telephone: +44-865-273211
-
-
- Article 58330 (1192 more) in comp.lang.c:
- From: bob@black.ox.ac.uk (Bob Douglas)
-
- Subject: Re: ******* DATES *********
- Date: 23 Oct 92 13:31:12 GMT
- Originator: bob@black
-
- In article <BwJGJw.Fn3@sci.kun.nl> hansm@cs.kun.nl (Hans Mulder) writes:
- >In <1992Oct21.183443.27418@black.ox.ac.uk> bob@black.ox.ac.uk (Bob Douglas) wri
- tes:
- >
- >>Hence in the sixteenth century Pope Gregory XIII authorized a revision of
- >>the calendar, and decreed that
- >
- >> (1) Centennial years should in future no longer be leap years
- >> unless they were divisible by 400 (i.e. 1600, 2000, 2400
- >> are leap years; 1700, 1800, 1900 are not). Non-centennial
- >> years should continue to be leap years if they are
- >> divisible by 4.
- >
- >> (2) Thursday 4 October 1582 (Julian calendar) would be followed
- >> by Friday 15 October 1582 (Gregorian calendar). The gap of
- >> 10 days corrected the accumulated error in the Julian
- >> calendar.
- >
- >Errhm, I would think that the accumulated error was 12 day: the years
- >100, 200, 300, 500, 600, 700, 900, 1000, 1100, 1300, 1400 and 1500 had
- >been leap years, and under the new rules they shouldn't have been.
- >
- >Does anybody know why Gregory XIII skipped only 10 days?
- >
- >--
- >Puzzled,
- >
- >Hans Mulder hansm@cs.kun.nl
-
- I (who posted the above article) noticed this too. The Gregorian
- amendment to the Julian calendar is such that, if the Gregorian
- calendar is extrapolated backwards, the two calendars are in
- agreement in the third century (from 1 March 200 to 28 February 300)
- instead of in the first century (from 1 January 1 AD) when the
- Julian calendar was two days ahead of the Gregorian one (it is now
- 13 days behind). Why this is so I do not know.
-
- The Gregorian calendar was devised by Christopher Clavius (a 16-th
- century mathematician and astronomer) on instruction from Pope
- Gregory XIII. The ultimate reference to the design must be
-
- Christopher Clavius.
- Kalendarium Perpetuum. Cum Privilegio Summi Pontificis Et Aliorum Principum.
- Rome, Ex Officina Dominicae Basae. MDLXXXII. Cum Licentia Superiorum
-
- However, none of the British Library, The Bibliotheque National or the
- Library of Congress have copies. No doubt one is to be found in the Vatican
- archives.
-
- But all is not lost! An explanatory volume was also prepared (c.f. the
- ANSI C Rationale) also by Christopher Clavius:
-
- Romani Calendarii a Gregorio XIII. Pontifice Maximo Restituti Explicato.
- Rome, 1603
-
- Copies of this are available in the British Library and the Bibliotheque
- Nationale (but not the Library of Congress). And no, I haven't read it!!
-
- --
- Bob Douglas Computing Services, University of Oxford
- Internet: bob@oxford.ac.uk
- Address: 13 Banbury Road, Oxford OX2 6NN, UK
- Telephone: +44-865-273211
-
-
- Article 58338 (1191 more) in comp.lang.c:
- From: msb@sq.sq.com (Mark Brader)
-
- Subject: Re: ******* DATES *********
- Date: Fri, 23 Oct 92 16:43:59 GMT
-
- This thread *really* should be elsewhere, such as sci.astro or soc.history,
- but I'm not going to be the one to redirect it.
-
- In a nice table of Julian/Gregorian dates, Bob Douglas (bob@black.ox.ac.uk)
- writes:
-
- > Sweden (including Finland) 18 Feb 1753 - 1 Mar 1753
-
- This is correct, but is only part of the story. As Anders Berglund wrote
- back in 1986 in the newsgroup net.bugs, in Sweden they had the marvelous idea
-
- | ... to gradually adapt to the Gregorian style by dropping all leap
- | days, starting with the year 1700! Since this would bring us ONE day
- | closer for every fourth year it also would mean that Sweden was to have
- | a unique calendar for the FORTY years it would take to overbridge this
- | ten-day time slip!! Truly a solution of the "splendid isolation" type!
- |
- | However, it didn't work out that way. The king was away on endless
- | war-tours in Russia and the government at home neglected to fulfill
- | the plan (if there was a reason, I don't know it). So, when 1704 came
- | along they happily enjoyed their leap day, and the same happened in
- | 1708. When 1712 was in sight someone obviously had got tired of this
- | one-day-ahead-or-ten-days-after style. It was decided to make an end
- | to it by -- listen to this! -- going BACK to Julian style!
- |
- | This is why Sweden got two leap days in 1712, making a 30-day February!
- | Is there anything like this on record in any other coutry...?
-
- I should mention that there is at least one book in English (called
- "Winning Ways") which mentions this story and gets it wrong. The topic
- arose on rec.puzzles a while back and the above story was verified from
- Swedish sources.
-
- Finland was part of the territory that Sweden and Russia were fighting over,
- I understand; without knowing the details of that war, I couldn't say
- how much of Finland also suffered this calendrical quirk.
-
- Hans Mulder (hansm@cs.kun.nl) asks:
-
- > > (2) Thursday 4 October 1582 (Julian calendar) would be followed
- > > by Friday 15 October 1582 (Gregorian calendar). The gap of
- > > 10 days corrected the accumulated error in the Julian
- > > calendar.
- >
- > Errhm, I would think that the accumulated error was 12 day: the years
- > 100, 200, 300, 500, 600, 700, 900, 1000, 1100, 1300, 1400 and 1500 had
- > been leap years, and under the new rules they shouldn't have been.
- > Does anybody know why Gregory XIII skipped only 10 days?
-
- Dating from the birth of Christ wasn't adopted in his own time -- if it
- had been, presumably the correct year of his birth would have been used!
- The idea was apparently to restore the calendar alignment that existed
- around the time when this dating *was* adopted. I don't know why the skip
- was 10 days rather than 9 to match the year of the Council of Nicaea (325),
- which established a number of Christian practices -- I assume that "AD"
- dating was one of them. The British law that I mentioned specifically
- refers to the era of that council (which it spells Nice).
- --
- Mark Brader "...the government is simply a bunch of people
- SoftQuad Inc. we've hired to protect ourselves from thieves and
- Toronto murderers and rapists and other governments..."
- utzoo!sq!msb, msb@sq.com -- Bill Stewart
-
- This article is in the public domain.
-
-
- Article 58353 (1190 more) in comp.lang.c:
- From: dik@cwi.nl (Dik T. Winter)
-
- Subject: Re: ******* DATES *********
- Date: 24 Oct 92 01:53:34 GMT
-
- In article <1992Oct23.133112.26368@black.ox.ac.uk> bob@black.ox.ac.uk (Bob Dougl
- as) writes:
- > In article <BwJGJw.Fn3@sci.kun.nl> hansm@cs.kun.nl (Hans Mulder) writes:
- > >Errhm, I would think that the accumulated error was 12 day: the years
- > >100, 200, 300, 500, 600, 700, 900, 1000, 1100, 1300, 1400 and 1500 had
- > >been leap years, and under the new rules they shouldn't have been.
- > >
- > >Does anybody know why Gregory XIII skipped only 10 days?
- > >
- > I (who posted the above article) noticed this too. The Gregorian
- > amendment to the Julian calendar is such that, if the Gregorian
- > calendar is extrapolated backwards, the two calendars are in
- > agreement in the third century (from 1 March 200 to 28 February 300)
- > instead of in the first century (from 1 January 1 AD) when the
- > Julian calendar was two days ahead of the Gregorian one (it is now
- > 13 days behind). Why this is so I do not know.
- >
- The reason is simple. The calendar reform had two main purposes, of which
- one is generally known: to bring dates more in line with seasons throughout
- the years. The second (and in that time main) purpose was a new calculation
- for easter (and that is also the reason why protestants were reluctant and
- greek orthodox people are refusing to adopt the new calendar). The slight
- shift was to bring the start of spring closer to the 21nd of March (which
- was not the case with the start of the Julian calendar). The greek
- orthodox church adopted a slightly different calendar, but the first time
- you will see a difference is on 29 Feb 2700 (I think, this is from memory),
- which does occur in the Gregorian calendar but not in the Greek orthodox one.
- --
- dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland
- home: bovenover 215, 1025 jn amsterdam, nederland; e-mail: dik@cwi.nl
- SHAR_EOF
- cat << \SHAR_EOF > data
- ; beginning of Julian dates
- 0 -4713 1 1 Mon 0
- 1 -4713 1 2 Tue 1
- 2 -4713 1 3 Wed 2
- 3 -4713 1 4 Thu 3
- ;
- ; Julian calendar repeats every 4 years, at 365*4+1 = 1461 day intervals
- 260424 -4000 1 1 Thu 0
- ; 1461 4
- 261885 -3996 1 1 Tue 0
- ; 1461 4
- 263346 -3992 1 1 Sun 0
- ;
- ; Julian dates near 1 AD (there was no year 0)
- 1721420 -1 12 28 Tue 362
- 1721421 -1 12 29 Wed 363
- 1721422 -1 12 30 Thu 364
- 1721423 -1 12 31 Fri 365
- 1721424 1 1 1 Sat 0
- 1721425 1 1 2 Sun 1
- 1721426 1 1 3 Mon 2
- ;
- ; usual transition dates are:
- ;
- ; 2299161 = October 5/15, 1582, as in Rome, or
- ; 2361222 = September 3/14, 1752, as in the United Kingdom
- ; and the Colonies (default)
- ;
- ; Julian dates near the transition...
- ;
- 2361220 1752 9 1 Tue 244
- 2361221 1752 9 2 Wed 245
- 2361222 1752 9 14 Thu 246
- 2361223 1752 9 15 Fri 247
- T2299161 ; as in Rome
- 2299159 1582 10 3 Wed 275
- 2299160 1582 10 4 Thu 276
- 2299161 1582 10 15 Fri 277
- 2299162 1582 10 16 Sat 278
- ;
- ; Apart from the 4000 year correction, the Gregorian calendar repeats
- ; every 400 years, or at ((365*4+1)*25-1)*4+1 = 146097 day intervals
- 2302526 1592 1 1 Wed 0
- ; 146097 400
- 2448623 1992 1 1 Wed 0
- ; 146097 400
- 2594720 2392 1 1 Wed 0
- ; 146097 400
- 2740817 2792 1 1 Wed 0
- ;
- ; Including the 4000 year correction, the Gregorian calendar repeats
- ; at (((365*4+1)*25-1)*4+1)*10-1 = 1460969 day intervals
- 2302526 1592 1 1 Wed 0
- ;1460969 4000
- 3763495 5592 1 1 Tue 0
- ;1460969 4000
- 5224464 9592 1 1 Mon 0
- ;1460969 4000
- 6685433 13592 1 1 Sun 0
- ;
- ; The USNO time service reports the Modified Julian Date (MJD),
- ; which is figured by subtracting a constant (2,400,000.5) from the
- ; Julian Date as of the preceding midnight.
- ;
- ; For example, the MJD for 7 Jul 92 was 48806
- ; offset 2400000.5
- ; JD at midnight was 2448806.5
- ; JD at noon was 2448807
- ;
- 2448807 1992 7 3 Fri 184
- ;
- ; checks on day-of-week calculation...
- ; "black Tuesday"
- 2425914 1929 10 29 Tue 301
- ; "a day that will live in infamy"
- 2430336 1941 12 7 Sun 340
- ; "black Monday"
- 2447088 1987 10 19 Mon 291
- SHAR_EOF
- cat << \SHAR_EOF > makefile
- CFLAGS= -v
- tjul.exe: tjul.obj julcal.obj
- $(CC) -v tjul.obj julcal.obj
- julcal.obj: julcal.c
- tjul.obj: tjul.c julcal.h
-
- distrib: julcal10.zip julcal.sh
- julcal10.zip: julcal.c julcal.h tjul.c dates.txt data makefile makefile.ux
- echo Julian date routines |pkzip -uoz julcal10 julcal.c julcal.h tjul.c dates.txt data makefile makefile.ux
- julcal.sh: julcal.c julcal.h tjul.c dates.txt data makefile makefile.ux
- shar julcal.c julcal.h tjul.c dates.txt data makefile makefile.ux >julcal.sh
-
- clean:
- erase *.obj
- erase tjul.exe
- SHAR_EOF
- cat << \SHAR_EOF > makefile.ux
- #CC=gcc
- tjul: tjul.o julcal.o
- $(CC) $(CFLAGS) -o tjul tjul.o julcal.o
- julcal.o: julcal.c
- gcc -DMKTIME -c julcal.c
- tjul.o: tjul.c julcal.h
-
- distrib: julcal10.zip
- julcal10.zip: julcal.c julcal.h tjul.c dates.txt data makefile makefile.ux
- zip -o julcal10 julcal.c julcal.h tjul.c dates.txt data makefile makefile.ux
-
- clean:
- rm *.o tjul
- SHAR_EOF
- # End of shell archive
- exit 0
-