< previous page page_216 next page >

Page 216
(continued)
Listing 8.10
   switch (dow)
          {
          case DOW_TUESDAY:
               jd2 -= 1.0;
               break;
          case DOW_WEDNESDAY:
               jd2 -= 2.0;
               break;
          case DOW_THURSDAY:
               jd2 -= 3.0;
               break;
          case DOW_FRIDAY:
               jd2 += 3.0;
               break;
          case DOW_SATURDAY:
               jd2 += 2.0;
               break;
          case DOW_SUNDAY:
               jd2 += 1.0;
               break;
          }
   week_number = ( (int) (jd1 - jd2) ) / 7 + 1;
   return (week_number);
}

Listing 8.11 iso_first_day_of_week ()
/* ifirstda.c
   +-------------------------------------------+
   |   Copyright (C) 1995 by Lance W. Latham.  |
   |          All rights reserved.             |
   +-------------------------------------------+
   Routine returns the date which is the first 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 Monday.


   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 first 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.

 
< previous page page_216 next page >