DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download
Index: ┃ R T

⟦7e593493e⟧ TextFile

    Length: 5865 (0x16e9)
    Types: TextFile
    Names: »README«

Derivation

└─⟦a0efdde77⟧ Bits:30001252 EUUGD11 Tape, 1987 Spring Conference Helsinki
    └─ ⟦this⟧ »EUUGD11/euug-87hel/sec1/yearlength/README« 

TextFile



  This collection of functions attempts to provide the number of
days in a year based upon a selected year and country.  It is
being posted because of a promise I made to the readers of net.lang.c.

  There are basically three levels of that can be used in to calculate
how long a year is:

    1. Divisibility by 4 -- this works for the years 1901-2099 and,
       as a result, is suitable for nearly all programs.  It can be
       coded as:                     or a faster version:
	   
	   if (year % 4 == 0)             if ((year & 0x03) == 0)
	       days_in_year = 366;            days_in_year = 366;
	   else                           else
	       days_in_year = 365;            days_in_year = 365;


    2. Gregorian rules -- this works from the year after your country
       adopted the Gregorian calendar through the forseeable future.
       It can be coded as:

	   if (year%4 == 0 && year%100 != 0 || year%400 == 0)
	       days_in_year = 366;
	   else
	       days_in_year = 365;

       or slightly faster (as Karl Heuer suggested to me via mail):

	   if ((year%4 == 0) && (year%100 != 0 || year%400 == 0))
	       days_in_year = 366;
	   else
	       days_in_year = 365;

       or (depending on how the remainder operator is implemented)
       this is up to 5 times faster by taking advantage of some
       common factors of 100 and 400:

	   register int ndiv100;	/* Boolean for not divisible by 100 */

	   if ((year&0x3)==0 && (ndiv100=year%100) || (year&0xF)==0 && !ndiv100)
	       days_in_year = 366;
	   else
	       days_in_year = 365;

       or even faster by using Karl Heuer's suggestion of reordering
       the expression:

	   if ((year&0x3)==0 && ((year&0xF)==0 || year%100!=0))
	       days_in_year = 366;
	   else
	       days_in_year = 365;

       I believe that this is the fastest possible check for leap years.
       Does anyone know of a fast check for remainders so that the "% 100"
       test can be speeded up?

    3. Country-dependent rules --  which is what this collection of
       functions attempt to do.  It gets messy.



BACKGROUND INFORMATION OF COUNTRY-DEPENDENT RULES
-------------------------------------------------

  When dealing with calendars based on different epochs (e.g., Egyptian,
Roman Republican, Julian, Augustan, Christian/Gregorian, Jewish, Muslim,
Chinese, Mayan, Japanese) it is easier to convert dates into a scheme that
has a starting date older than that of any of the epochs.  Such a scheme
was invented by J. Scalinger in 1583.  

  However, all years as used by this package are those of the Christian
era because that is the most common representation used throughout the
world.  Valid years are 1AD through 9999AD.   There is no year 0.  Negative
years (those BC) are not used in this program because the Julian calendar
was still being changed by Augustus in 8BC (renamed the month Sextilus
to August and changed the number of days in several months).

  The argument may be made that going to years before the 4th Century AD
is fruitless.  It is about that time that the Emperor Constantine (he had
previously converted to Christianity) made the 7 day week official
throughout the Roman Empire.  The Celtic calendar had 8 days but the
calendar Moses took with him from Egypt had 7.  It's fascinating how
calendars tie in with history.  Had the Nazis won WW2, we now might have
a calendar based on the birth of Hitler!  And it was about that time that
the year of Christ's birth, instead of the start of City of Rome, was
suggested as the basis for counting years.

  It is not possible to guarentee the accuracy for very early dates.  
The references that I consulted occasionally would disagree on dates.
There are many difficulties in arriving at a definitive answer for
a region's calendar because of national and supernational influences.
Some of these are: wars that change boundaries; country-dwellers
resistance to the calendar change wrought by the city-based government;
and religous differences over what is the "right" calendar.  Many
Protestants chose to be "wrong with the calendar rather than right with
the Pope".  For examples of such turmoil see any of the *_early() functions.

  An assumption that I used to decide when a country should be put
in the switched-to-Gregorian calendar list, if I could not find a
clear date, was to take the switch over date of its ruling country.
All of the South American countries use Spain's date even though
the reality of when countries actually changed is much more complex.
The many British colonies use the same year as Great Britain, 1752.
See canada_early() for a the type of trouble caused by two dominant
countries: Britain and France.  So, a plea to those out there that
want to rule the world: When you do take over, see to that the rules
are observed consistently!  It makes everything much easier :-)

  Some countries did not transistion directly from the Julian to the
Gregorian calendar.  An alternate calendar was tried or the calendar
was modified only slightly.  See the france_early(), sweden_early(),
and ussr_early() functions.

  Some of the date/country pairs are historically naive.  By all
rights, Israeli dates should not exist before 1948.  However because
the country of Palestine was following the same year rules prior to
1948, I allowed it.  Many, many such arguments can be made (e.g., how
to handle dates in years before the USA gained independence or even
before it was "discovered" by Columbus/stray Vikings/Anasazi Indians.
Change the dates to make yourself happy.

  The list of countries is not complete.  I have no intention of 
extending it to cover all current, past, and future countries.  If
you want to do it yourself, feel free to hack it up.

  I would appreciate the reception of any changes/corrections you make!


Bob Devine
November 1986 (Gregorian style numbering)