|
|
|
|
|
|
|
6.2.1.2.2 number_of_DOWs_in_month () |
|
|
|
|
|
|
|
|
Returns the number of days of the week (DOWs) of a given type for a given month and year. For example, this routine (Listing 6.2) returns the number of Sundays in February 1809. |
|
|
|
|
| Listing 6.1 | |
|
|
|
|
/*
Check that the resulting date is still within the range of the
input month and year. Restriction of 'n' to values less than 6
prevents the calculated date from matching on month but falling
into a different year.
*/
if ( (date.month != month) || (date.year != year) )
date = make_date (0, 0, 0);
return (date);
} |
|
|
|
|
|
|
| Listing 6.2 number_of_DOWs_in_month () | |
|
|
|
|
/* num_dows.c
+-------------------------------------------+
| Copyright (C) 1995 by Lance W. Latham. |
| All rights reserved. |
+-------------------------------------------+
Returns the number of days of the week (DOWs) of a given type for a given month
and year. E.g., this routine returns the number of Sundays in February, 1809.
INPUTS:
1. dow_index, type int, the index indicating which day of the week is
desired. Valid values are 0 (Sunday) through 6 (Saturday).
2. month, type int, the month desired. Valid values are 1 through 12,
with the usual assignment (1 = January, 12 = December).
3. year, type int, the year desired. Valid values are the range for type int.
OUTPUTS:
1. Returned by routine, type int, the number of days of the week of
the given type in the particular month and year specified.
NOTES:
1. The routine returns an error indication of zero, in the following events:
1.1. The value of 'dow_index' is invalid.
1.2. The value of 'month' is invalid.
1.3. The maximum number of DOWs of the specified type is not
4 or 5, except in the special case of October 1582.
2. The case of October 1582 is a special case. This month contains the
Julian-Gregorian calendar boundary, and contains only 21 days.
The date 1 October 1582 is a Monday, and 31 October 1582 is a
Sunday. There are exactly 3 occurences of each DOW in this one special case.
|
|
|
|
|
|
|
|