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@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] 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 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 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