< previous page page_112 next page >

Page 112
6.2.1.2.3
Nth_DOW_after_date ()
Returns the date corresponding to the Nth day of the week on or after a given date. That is, this routine (Listing 6.3) returns the date for the fourth Thursday on or after 02 March 1994 or the first Tuesday on or after Christmas of 1866.
(continued)
Listing 6.2
   3. This routine depends upon the fact that all months (except the
      special case above) in the Western calendar contain either
      4 or 5 occurences of a given DOW. Therefore, the routine works
      in four basic steps:
      3.1. Eliminate invalid inputs, returning '0'.
      3.2. Return '3' for the special case of October 1582.
      3.3. Look for the 5th DOW of the given type in the month and year.
           If this is found, return '5', since 5 is a maximum.
      3.4. If the 5th DOW is not found, look for a 4th DOW of the
           given type. If this is found, return '4', since a 5th DOW does
           not exist, and a 3rd DOW cannot be a maximum. If a 4th DOW is
           not found, return a '0' indicator.
*/


#include "dateinfo.h"
#include "scdtl_4.h"


int number_of_DOWs_in_month (int dow_index, int month, int year)
{
   struct DATE_INFO date;


   if ( (dow_index < 0) || (dow_index > 6) )
      return (0);
   if ( (month < 1) || (month > 12) )
      return (0);
   if ( (year == 1582) && (month == 10) )
      return (3);


   date = Nth_DOW_of_month (5, dow_index, month, year);


   if (date.day != 0)
      return (5);
   else
      {
      date = Nth_DOW_of_month (4, dow_index, month, year);

      if (date.day != 0)
         return (4);
      else
         return (0);
      }
}



 
< previous page page_112 next page >