< previous page page_100 next page >

Page 100
(continued)
Listing 5.11
   (Sunday) through 6 (Saturday). The leap year functions return 0 or 1,
   so a simple formula relates year type by this definition to DOW and
   leap year. I.e.,


   year type = ((DOW index of 01 JAN) + (7 * (leap year indicator))


3. The year A.D. 1582 is the boundary year between the Julian and
   Gregorian calendars. The Gregorian calendar was implemented on
   15 October 1582, which immediately followed 04 October 1582.


   Therefore, the year 1582 is a special case. This routine returns
   the year type as of 01 January 1582, which defines 1582 as a year in
   the Julian calendar, and therefore a year type '2'.


   For dates in the range 15 October 1582 to 31 December 1582, however,
   the year type is '6', since these dates correspond to the type
   '6' calendar. For this one single year in the Western calendar,
   therefore, there are two year types.
*/


#include "scdtl_2.h"


int year_type (int year)
{
   double jd;
   int index;
   struct DATE_INFO date;


   date = make_date (year, 1, 1);
   jd = date_to_JD0 (&date);
   index = day_of_week_index_JD0 (jd) + 1;


   if (year < 1582)
      {
      if (julian_leap_year (year))
         index += 7;
      }
   else
      {
      if (gregorian_leap_year (year))
         index += 7;
      }


   return (index);
}

 
< previous page page_100 next page >