< previous page page_218 next page >

Page 218
(continued)
Listing 8.11
   if (week == 53)
      {
      if (!( (yt == 5) || (yt == 11) || (yt == 12) ))
         return (date);
      }


   if (yt > 7)
      yt -= 7;


   date = tab [yt];
   date.year += year;
   jd = date_to_JD0 (&date);
   jd += (double) ((week - 1) * 7);
   date = JD0_to_date (jd);


   return (date);
}

Listing 8.12 iso_last_day_of_week ()
/* ilastday.c


   +-------------------------------------------+
   |   Copyright (C) 1995 by Lance W. Latham.  |
   |          All rights reserved.             |
   +-------------------------------------------+


   Routine returns the date which is the last day of the week for
   the given year and week number. The definition of week number follows
   the ISO rule. This date is always a Sunday.


   INPUTS:
   1. year, type int, the year Anno Domini in the Western (Julian/
      Gregorian) calendar system.
   2. week, type int, the week number, as defined by the ISO rule. Valid values
      are 1 through 53. Week 53 is only valid for certain types of year.


   OUTPUTS:
   1. Returned by routine, a DATE_INFO structure containing the date which
      is the last day of the given week number, within the given year.


   NOTES:
   1. The year is assumed to be a year Anno Domini, in the Western calendar.
   2. The routine returns a date of {0, 0, 0} for invalid week numbers.
      Week numbers outside the range of 1 to 53 are invalid. Week number
      53 is valid only for year types 5, 11 and 12. In this application,
      the week number refers to the given year, and hence means week number
      at the END of the year. A calendar year of type 6, 7 or 13 may BEGIN
      with a week number 53, but the week number refers to a week which
      begins in the preceding year.
   3. The 'year type' refers to the value, 1 through 14, which identifies
      the 'type' of year in the Western calendar. Each year begins with a
      certain day of the week (DOW), and is either a common or leap year.
      All years with the same year type are structurally identical.

 
< previous page page_218 next page >