< previous page page_118 next page >

Page 118
6.2.1.2.6
Nth_full_weekend ()
Returns the date of the Saturday beginning the Nth full weekend of the given month and year (Listing 6.6).
Listing 6.6 Nth_full_weekend ()
/* nfulwknd.c


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


   Returns the date of the Saturday beginning the Nth full weekend
   of the given month and year.


   INPUTS:
   1. n, type int, the ordinal identifier for the desired full weekend
      in the given month and year. Valid values are 1 through 5, in
      general. Values 1 through 3 are valid for all months and years.
      Value 4 is valid for most months and years, value 5 is valid for
      some months and years.
   2. month, type int, the month (1 through 12) for which the Nth
      full weekend is desired.


   3. year, type int, the year (A.D., in the Western calendar) for
      which the Nth full weekend is desired.


   OUTPUTS:
   1. Returned by routine, a DATE_INFO structure containing the date of
      the Saturday beginning the Nth full weekend of the given year and
      month. In the event of error, this date is set to all zeroes.


   NOTES:
   1. A weekend is considered to be a two-day period, consisting of
      a Saturday and the Sunday which immediately follows.
   2. A 'full' weekend is a weekend in which both days occur in the same month.
   3. The routine returns a date of all zeroes in the event of error.
      Possible errors are:


      3.1. Input 'n' is invalid (less than 1 or greater than 5).
      3.2. The input month does not contain an 'n'th Saturday.
      3.3. The input month does not contain an 'n'th full weekend.


   4. The following table may be used to derive valid values for 'n',
      where N is the number of full weekends and M is the minimum
      number of days in a month required to produce N full weekends:


      N : 1 2  3  4  5  6
      M : 2 9 16 23 30 37


      Therefore, the five following conclusions may be drawn:


      4.1. All months can have 4 full weekends, since all months have
           at least 23 days.
      4.2. February can never have 5 full weekends, since 30 days
           are required, and February can only have 29 days.

 
< previous page page_118 next page >