< previous page page_119 next page >

Page 119
(continued)
Listing 6.6
     4.3. All months except February can have 5 full weekends, since
          all months except February have at least 30 days.
     4.4. No month can have 6 full weekends, since no month has the
          minimum required 37 days.
     4.5. The expression for M, in terms of N, is (7N - 5).


   5. We may consider the reverse situation, involving the maximum number
      of days which may elapse without the occurrence of a full weekend.
      In all cases, this situation involves a month which starts on Sunday.
      For the following table, N is the number of full weekends, and M is
      the maximum number of days possible without producing N full weekends:


      N : 1  2  3  4  5
      M : 7 14 21 28 35


      Therefore, we may draw the following additional conclusions:


      5.1. February can have a maximum of only 3 full weekends, in the
           case of common years, when 1 February is a Sunday (type 5 year).
      5.2. No other month can have only 3 full weekends, since all other
           months have more than 28 days (including February in leap years).
      5.3. The expression for M, in terms of N, is simply (7N).
*/


#include "scdtl_2.h"
#include "scdtl_4.h"


struct DATE_INFO Nth_full_weekend (int n, int month, int year)
{
   struct DATE_INFO date_0, date_1, date_2;
   double jd;


   date_0 = make_date (0, 0, 0);


   if ( (n < 1) || (n > 5) )
      return (date_0);


   date_1 = Nth_DOW_of_month (n, DOW_SATURDAY, month, year);


   if ((date_1.year == 0) && (date_1.month == 0) && (date_1.day == 0))
      return (date_0);
   else
      {
      jd = date_to_JD0 (&date_1);
      jd = jd + 1.0;
      date_2 = JD0_to_date (jd);


      if (date_2.month == month)
         return (date_1);
      else
         return (date_0);
      }
}



 
< previous page page_119 next page >