home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume7 / yearlength / early.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-01-19  |  15.2 KB  |  530 lines

  1. #include <stdio.h>
  2.  
  3.  
  4. /**********************************************************************
  5. *
  6. * unknown_calendar() -- ignorance place holder
  7. *
  8. *     This is for countries that I don't know about.  It is used for
  9. *   the Muslim, Celtic, Chinese, Mayan, and other calendars.
  10. *
  11. **********************************************************************/
  12. int unknown_calendar(year, change_year)
  13.     int year;
  14.     int change_year;
  15. {
  16.     return(-1);
  17. }
  18.  
  19.  
  20. /**********************************************************************
  21. *
  22. * julian() -- return length of year based on Julius Caesar/Sosigenes rule
  23. *
  24. *     Actually could go back to 45 BC, but why?
  25. *     Calling routine allows no years before 1 AD 
  26. *
  27. **********************************************************************/
  28. int julian(year, change_year)
  29.     int year;
  30.     int change_year;
  31. {
  32.     int length = 365;
  33.  
  34.  
  35.     if ((year & 03) == 0)
  36.     length = 366;
  37.  
  38.     if (year == change_year)
  39.     switch (change_year / 100)
  40.     {
  41.     case 20:
  42.         /* 2000 - 2099 */
  43.         /* 2000 is a leap year; fall through */
  44.     case 19:
  45.         /* 1900 - 1999 */
  46.         return(length-13);
  47.     case 18:
  48.         /* 1800 - 1899 */
  49.         return(length-12);
  50.     case 17:
  51.         /* 1700 - 1799 */
  52.         return(length-11);
  53.     case 16:
  54.         /* 1600 - 1699 */
  55.         /* 1600 is a leap year, fall through */
  56.     case 15:
  57.         /* 1500 - 1599 */
  58.         return(length-10);
  59.     }
  60.  
  61.     return(length);
  62. }
  63.  
  64.  
  65. /**********************************************************************
  66. *
  67. * belgium_early() -- handle problem caused by the change to Gregorian
  68. *                    overlapping two years
  69. *
  70. **********************************************************************/
  71. int belgium_early(year, change_year)
  72.     int year;
  73.     int change_year;
  74. {
  75.     /* the days 12/25/1582 - 1/5/1583 were dropped */
  76.     if (year == change_year || year == change_year-1)
  77.         return(360);
  78.  
  79.     /* do normal Julian rules */
  80.     if ((year & 03) == 0)
  81.     return(366);
  82.     else
  83.     return(365);
  84. }
  85.  
  86.  
  87. /**********************************************************************
  88. *
  89. *  canada_early() -- deal with conflict between French rules and
  90. *                    British rules for dates
  91. *
  92. *   France changed to Gregorian 12/10/1582 (Julian)
  93. *   Britain changed to Gregorian 09/05/1752 (Julian)
  94. *   therefore, Canada changed on ??/??/????
  95. *
  96. *   Some guesses can be made based on the individual provinces/territories:
  97. *
  98. *     Alberta                  British rules likely apply
  99. *     British Columbia         British rules definitely apply
  100. *     Manitoba                 likely British rules (def. British after 1763)
  101. *     New Brunswick            France and British alternated control
  102. *     Newfoundland             contested until 1713 when became British
  103. *     Nova Scotia              British after 1713
  104. *     Ontario                  French first then British after 1759
  105. *     Prince Edward Island     follows Ontario rules (?)
  106. *     Quebec                   Britain gained in 1763 with Treaty of Paris
  107. *     Saskatchewan             British rules apply
  108. *     Yukon Territory          first Russian then British after 1840 (?)
  109. *
  110. **********************************************************************/
  111. int canada_early(year, change_year)
  112.     int year;
  113.     int change_year;
  114. {
  115.     /* calculate using British change year for Canada's */
  116.     return(julian(year, change_year));
  117. }
  118.  
  119.  
  120. /**********************************************************************
  121. *
  122. * china_early() -- previous to using the Gregorian calendar, China
  123. *                  used a 12 (ordinary year) or 13 (full year) month
  124. *                  calendar that operated in 60 year cycles
  125. *                  Years began with the lunar month that had the sun
  126. *                  enter the zodiacal sign Aquarius
  127. *
  128. *                  Jesuit missionaries tried to reform the calendar
  129. *                  when they arrived in the 1600s.  I haven't found
  130. *                  out the full ramifications of that attempt.  What I
  131. *                  have seen is that the calendar was again changed by
  132. *                  the Chinese after that; this introduced some errors.
  133. *
  134. *                  Now, what that means for converting years is
  135. *                  a lot of work...
  136. *
  137. **********************************************************************/
  138. int china_early(year, change_year)
  139.     int year;
  140.     int change_year;
  141. {
  142.     /* punt */
  143.     return(-1);
  144. }
  145.  
  146.  
  147.  
  148. /**********************************************************************
  149. *
  150. * france_early() -- deal with France's use of the Republic calendar
  151. *                   for the years 1793-1805
  152. *
  153. *    The Revolutionary Calendar was a base 10 calendar.  That is, it
  154. *  had 360 days arranged in 12 months of 30 days plus 5 or 6 unnumbered
  155. *  days that were added to the end of the last month.  Each day was 10
  156. *  hours of 100 minutes of 100 seconds long.
  157. *
  158. *    It was rejected after over a decade of use mainly because of its
  159. *  opposition from religious groups who did not approve of weeks that
  160. *  were seven days long.
  161. *
  162. **********************************************************************/
  163. int france_early(year, change_year)
  164.     int year;
  165.     int change_year;
  166. {
  167.     /* Republic --> Gregorian */
  168.     if (year == 1806)
  169.     return(365);    /* ? */
  170.  
  171.     /* Republic Calendar -- follows Julian leap-year rule */
  172.     if (year > 1793  ||  year < 1806)
  173.     {
  174.     if ((year & 03) == 0)
  175.         return(366);
  176.     else
  177.         return(365);
  178.     }
  179.  
  180.     /* Gregorian --> Republic */
  181.     if (year == 1793)
  182.     return(365);
  183.  
  184.     /* Gregorian */
  185.     if (year > 1582  ||  year < 1793)
  186.     {
  187.     if ((year&0x3)==0 && ((year&0xF)==0 || year%100))
  188.        return(366);
  189.     else
  190.        return(365);
  191.     }
  192.  
  193.     /* Julian --> Gregorian */
  194.     if (year == 1582)
  195.     return(365-10);        /* dropped the days 12/10 - 12/20 */
  196.  
  197.     /* Julian */
  198.     if ((year & 03) == 0)
  199.     return(366);
  200.     else
  201.     return(365);
  202. }
  203.  
  204.  
  205. /**********************************************************************
  206. *
  207. * german_early() -- deal with problem of country adopting the
  208. *                   Gregorian calendar in parts
  209. *
  210. *  Gregorian calendar was adopted in overlapping parts:
  211. *      10/16/1583   Bavaria
  212. *      11/14/1583   the Catholic population
  213. *       3/01/1682   Strassburg
  214. *      11/15/1699   the Protestant population
  215. *      12/12/1700   Utrecht
  216. *
  217. *  I have the last date (1700) in the table for the entire country.
  218. *  If you want more accuracy in dealing with the partial changes,
  219. *  make modifications to the country table and the following code.
  220. *
  221. **********************************************************************/
  222. int german_early(year, change_year)
  223.     int year;
  224.     int change_year;
  225. {
  226.     /* deal with change-over date */
  227.     if (year == change_year)
  228.     return(366-11);            /* 1700 is a leap year */
  229.  
  230.     /* else, do normal Julian rules */
  231.     if ((year & 03) == 0)
  232.     return(366);
  233.     else
  234.     return(365);
  235. }
  236.  
  237.  
  238.  
  239. /**********************************************************************
  240. *
  241. * greece_early() -- country did not change all at one time
  242. *
  243. *    The changes that occurred are:
  244. *
  245. *        07/15/1916  Calendar change adopted by all except...
  246. *        09/30/1923  ...the Greek Church, which finally accepted it
  247. *
  248. *    The table uses the latter date.  Hack this if you don't like it.
  249. *    A warning:  one reference seemed to indicated (it wasn't clear if
  250. *    it had been just proposed or it was accepted) that Greece is using a
  251. *    modified Julian calendar that has two leap centuries out of *nine*.
  252. *    If this is true, then dates after 2800 will be different from
  253. *    the Gregorian calendar.
  254. *
  255. **********************************************************************/
  256. int greece_early(year, change_year)
  257.     int year;
  258.     int change_year;
  259. {
  260.     /* do change-over year */
  261.     if (year == change_year)
  262.     return(365-13);        /* 1923 was not a leap year */
  263.  
  264.     /* do normal Julian rules */
  265.     if ((year & 03) == 0)
  266.     return(366);
  267.     else
  268.     return(365);
  269. }
  270.  
  271.  
  272. /**********************************************************************
  273. *
  274. * iran_early() -- uses the Monarchic Calendar
  275. *
  276. *  I don't know how if or when Gregorian was used.  The Muslim
  277. *  calendar may still be used (it is a 12 month calendar with a 30
  278. *  year cycle;  eleven days are added over the cycle) for daily or
  279. *  religious or even Government functions.
  280. *
  281. **********************************************************************/
  282. int iran_early(year, change_year)
  283.     int year;
  284.     int change_year;
  285. {
  286.     return(-1);
  287. }
  288.  
  289.  
  290. /**********************************************************************
  291. *
  292. * japan_early() -- deal with Japanese lunar calendar
  293. *
  294. *   Unfortunately, I have been unable to find any detailed information
  295. *   on the calendar used prior to the adoption of the Gregorian calendar.
  296. *
  297. *   If anyone has some info, I'd like to receive it.
  298. *
  299. **********************************************************************/
  300. int japan_early(year, change_year)
  301.     int year;
  302.     int change_year;
  303. {
  304.     return(-1);
  305. }
  306.  
  307.  
  308. /**********************************************************************
  309. *
  310. * netherlands_early() -- deal with scattered adoption
  311. *
  312. *  Adoption of the Gregorian calendar went by the following cities:
  313. *     12/15/1582   Holland, Zeeland, Brabant, Vlaandern
  314. *     06/30/1700   Gelerland
  315. *     11/30/1700   Utrecht, Overijisol
  316. *     12/31/1700   Friesland, Groningen
  317. *     01/12/1701   Entire country consistent
  318. *
  319. **********************************************************************/
  320. int netherlands_early(year, change_year)
  321.     int year;
  322.     int change_year;
  323. {
  324.     /* Use date of total country adoption -- 1701 */
  325.     if (year == change_year)
  326.     return(365 - 11);
  327.  
  328.     /* do normal Julian rules */
  329.     if ((year & 03) == 0)
  330.     return(366);
  331.     else
  332.     return(365);
  333. }
  334.  
  335.  
  336. /**********************************************************************
  337. *
  338. * poland_early() -- deal with country's partial adoption dates
  339. *
  340. *  Dates for adoption are
  341. *      11/01/1582   Catholics (and Protestants?) adopt
  342. *      03/18/1918   Russian Poland changes (Civil War split)
  343. *      05/??/1923   Orthodox members adopt
  344. *
  345. **********************************************************************/
  346. int poland_early(year, change_year)
  347.     int year;
  348.     int change_year;
  349. {
  350.     /* Use date of total country adoption -- 1923 */
  351.     if (year == change_year)
  352.     return(365 - 13);
  353.  
  354.     /* do normal Julian rules */
  355.     if ((year & 03) == 0)
  356.     return(366);
  357.     else
  358.     return(365);
  359. }
  360.  
  361.  
  362. /**********************************************************************
  363. *
  364. * sweden_early() -- deal with bouncing leap day
  365. *
  366. *  Sweden took a half-step towards Gregorian but then retreated (think
  367. *  of it as sort of a single partner polka).
  368. *
  369. *       1700 -- made this year a non-leap year by dropping Feb 29th
  370. *       1712 -- went back to Julian calendar by making a Feb 30th !!
  371. *  2/18/1753 -- adopted Gregorian
  372. *
  373. **********************************************************************/
  374. int sweden_early(year, change_year)
  375.     int year;
  376.     int change_year;
  377. {
  378.     if (year == change_year)
  379.     return(365 - 11);
  380.  
  381.     if (year == 1700)
  382.     return(365);
  383.  
  384.     if (year == 1712)
  385.     return(367);
  386.  
  387.     /* do normal Julian rules */
  388.     if ((year & 03) == 0)
  389.     return(366);
  390.     else
  391.     return(365);
  392. }
  393.  
  394.  
  395. /**********************************************************************
  396. *
  397. * switzerland_early() -- deal with scattered adoption in country
  398. *
  399. *  Districts and their adoption dates (I had conflicting sources for
  400. *  the spelling of the district names)
  401. *
  402. *  Catholic districts 
  403. *     01/22/1584  Fribourg, Lucerne, Schwyz, Solothurn, Unterwalden, Uri, Zug
  404. *     01/17/1597  Appenzell
  405. *     03/01/1656  Valais (part did early in 1622)
  406. *
  407. *  Protestant districts 
  408. *     01/01/1701  Baselstradt, Bern, Biel, Cargous, Geneva, Neuchatel,
  409. *                 Schaffhausen, Thurgan, and Zurich
  410. *     12/20/1723  Appenzell
  411. *     01/12/1724  Glarus, St. Galen
  412. *     02/17/1812  Grisons
  413. *
  414. **********************************************************************/
  415. int switzerland_early(year, change_year)
  416.     int year;
  417.     int change_year;
  418. {
  419.     /* Use date of total country adoption -- 1724 (a leap year) */
  420.     if (year == change_year)
  421.     return(366 - 11);
  422.  
  423.     /* do normal Julian rules */
  424.     if ((year & 03) == 0)
  425.     return(366);
  426.     else
  427.     return(365);
  428. }
  429.  
  430.  
  431. /**********************************************************************
  432. *
  433. * turkey_early() -- deal with scattered adoption of new calendar
  434. *
  435. *  Adoption seemed to depend on regional background
  436. *
  437. *      1908  people with a European heritage
  438. *      1917  people with a Asian heritage (might be 1914)
  439. *
  440. **********************************************************************/
  441. int turkey_early(year, change_year)
  442.     int year;
  443.     int change_year;
  444. {
  445.     /* Use date of total country adoption -- 1917 */
  446.     if (year == change_year)
  447.     return(365 - 13);
  448.  
  449.     /* do normal Julian rules */
  450.     if ((year & 03) == 0)
  451.     return(366);
  452.     else
  453.     return(365);
  454. }
  455.  
  456.  
  457. /**********************************************************************
  458. *
  459. * usa_early() -- deal with state differences
  460. *
  461. *  The USA, for the most part, followed Great Britain's lead in the
  462. *  adoption of the the Gregorian calendar in 1752.  However, not all
  463. *  current states were part of the "country" at that time.  An easy
  464. *  lie is to say that all parts of the yet-to-be USA changed over on
  465. *  that date.  States like California were not even settled until
  466. *  about 1770.
  467. *
  468. *  The exceptions to the 1752 rule:
  469. *
  470. *  Alaska was owned by Russia until 1867. (see Russia's rules)
  471. *  Hawaii was an independent country that adopted Gregorian in 1893(?).
  472. *
  473. *  The non-states that operate under US protection are likewise exceptions
  474. *  to the rule (luckily, some were not inhabited or we'd have to hypnotise
  475. *  the native population to change their memory of previous calendars:-):
  476. *
  477. *  American Samoa became possesion 1899.
  478. *  Baker, Howland, and Jarvis Islands became possesions 1857(?).
  479. *  Panama Canal Zone was a possesion 1903-1979 (?).
  480. *  Canton and Enderbury Islands - 1939.
  481. *  Great Corn and Little Corn - leased from Nicaraugua for 99 years in 1914.
  482. *  Guam - obtained in 1898, lost to Japan 1941, regained in 1944.
  483. *  Johnston Island - came with Hawaii
  484. *  Midway Islands - 1867
  485. *  Phillipine Islands - was US territory 1898-1946
  486. *  Puerto Rico - Spain ceded to US in 1898
  487. *  Trust Territories of the Pacific (approx 2000 islands in W. Pacific)-1947
  488. *  Virgin Islands - bought from Denmark in 1917
  489. *  Wake Island - got from Spain 1898, Japan took 1941, regained in 1945
  490. *
  491. **********************************************************************/
  492. int usa_early(year, change_year)
  493.     int year;
  494.     int change_year;
  495. {
  496.     /* this is for the majority of the cases,  change if desired */
  497.     if (year == change_year)    /* 1752 */
  498.     return(366 - 11);
  499.  
  500.     /* do normal Julian rules */
  501.     if ((year & 03) == 0)
  502.     return(366);
  503.     else
  504.     return(365);
  505. }
  506.  
  507.  
  508. /**********************************************************************
  509. *
  510. * ussr_early() -- deal with scattered adoption of new calendar
  511. *
  512. * The changing calendar for the Soviet Union reflects a country
  513. * that was undergoing great changes.  The dates of change are:
  514. *
  515. *   1/1/1918 -- Western part changes to Gregorian
  516. *   2/5/1920 -- Eastern part changes to Gregorian
  517. *       1929 -- Entire country changed to a 5 day week and new calendar
  518. *       1932 -- Entire country changed to a 6 day week and new calendar
  519. *  6/27/1940 -- Chucked the non-standard calendar and returned to Gregorian
  520. *
  521. **********************************************************************/
  522. int ussr_early(year, change_year)
  523.     int year;
  524.     int change_year;
  525. {
  526.     /* the above is the present and total knowledge I have on the */
  527.     /* calendars used....  So, I'll punt and return(-1);          */
  528.     return(-1);
  529. }
  530.