|
|
|
|
|
|
|
6.2.1.2
Functions Implementing the Rules |
|
|
|
|
|
|
|
|
All days of observance that follow a regular rule can be implemented using one or more of the following functions. |
|
|
|
|
|
|
|
|
6.2.1.2.1 Nth_DOW_of_month () |
|
|
|
|
|
|
|
|
Returns the date corresponding to the Nth day of the week for a given month and year. For example, this routine (Listing 6.1) returns the date for the fourth Thursday of a given month and year, or the first Tuesday of a given month and year. |
|
|
|
|
| Listing 6.1 Nth_DOW_of_month () | |
|
|
|
|
/* nthdowmo.c
+-------------------------------------------+
| Copyright (C) 1995 by Lance W. Latham. |
| All rights reserved. |
+-------------------------------------------+
Returns the date corresponding to the Nth day of the week, for a given
month and year. I.e., this routine returns the date for "the fourth
Thursday" of a given month and year, or "the first Tuesday" of a given
month and year.
INPUTS:
1. n, type int, the number indicating the sequence number desired
for the chosen day of the week. Valid values cannot be less than
1, nor can they ever be greater than 5.
2. dow_index, type int, the index indicating which day of the week is
desired. Valid values are 0 (Sunday) through 6 (Saturday).
3. month, type int, the month. Valid values are 1 to 12, with the
usual assignment (1 = January, 12 = December).
4. year, type int, the year. Valid values are the values allowed by
the type int.
OUTPUTS:
1. Returned by routine, a DATE_INFO structure containing the date
corresponding to the 'N'th day of the week (DOW) in the month
and year given. In the event of an error, the routine returns
a date consisting of the year, month and day set to zero.
NOTES:
1. The routine returns a an error indication, of a date consisting
entirely of zeroes, in the following events:
1.1. The value of 'n' is invalid.
1.2. The value of 'dow_index' is invalid.
1.3. The value of 'month' is invalid.
1.4. The date which results from the calculation lies outside
the month and year input. This error would normally arise
by setting 'n' to a value greater than the maximum value
which it can have for the given month and year. The maximum
value for 'n' is 4, or 5, depending upon the month, year
and DOW input. The month of October of the year 1582 is the
single exception to this rule, for which case the maximum
value for 'n' is 3 for all values of 'dow_index'.
|
|
|
|
|
|
|
|