< previous page page_184 next page >

Page 184
(continued)
Listing 7.2
/*
   'ql' is the number of complete 4-year sets, consisting of 1461 days,
   which have elapsed. 'r' is the remainder of days within a single
   4-year set, after the complete sets have been accounted for as years.
*/


   ql = jdl / 1461L;
   r = (int) (jdl - (ql * 1461L));
   yl = (ql * 4L) - 4712L;
   y = (int) yl;


/* First year contains days 0365, and is the leap year in the set of 4. */


   if (r < 366)
      {
      jdate = j2jp_aux_1 (r);
      jdate.year = y;
      return (jdate);
      }


/* Second year contains days 366730, and is a common year of 365 days. */


   if (r < 731)
      {
      jdate = j2jp_aux_2 (r - 366);
      jdate.year = y + 1;
      return (jdate);
      }


/* Third year contains days 7311095, and is a common year of 365 days. */


   if (r < 1096)
      {
      jdate = j2jp_aux_2 (r - 731);
      jdate.year = y + 2;
      return (jdate);
      }


/* Fourth year contains days 10961460, and is a common year of 365 days. */


   jdate = j2jp_aux_2 (r - 1096);
   jdate.year = y + 3;
   return (jdate);
}


/*
   Auxiliary routine for JD0_to_julian_proleptic (). Assigns the month and day part
   of a DATE_INFO structure, given the remainder of modulo 1461 division, for a
   Julian leap year. Each set of 1461 days consists of one leap year and three
   common years. The first year is the leap year.
*/
struct DATE_INFO j2jp_aux_1 (int r)
{
   int m, stop;
   int tab [13] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366};
   struct DATE_INFO date;

 
< previous page page_184 next page >