|
|
|
| Listing 6.4 | |
|
|
|
|
2. dow_index, type int, the index indicating which day of the week is
desired. Valid values are 0 (Sunday) through 6 (Saturday).
3. date_in, pointer to a DATE_INFO structure containing the desired
starting date.
OUTPUTS:
1. Returned by routine, a DATE_INFO structure containing the date
corresponding to the 'Nth' day of the week (DOW) on or before the
date 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 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' of 'date_in' is invalid.
2. Note that this routine, unlike the 'Nth_DOW_of_month ()' routine
in this series, does NOT intercept result dates outside the month and
year of the input date. Thus, the 'thirty-seventh Tuesday on or before
the date of 01 December 1998" will return a legitimate date, not an
error.
3. This routine works in three basic steps:
3.1. Find the DOW of the given date.
3.2. Find the date of the first DOW matching the input DOW.
3.3. Find the date of the 'n' th DOW matching the input DOW.
4. Note that this routine returns dates ON or before a date. Therefore,
if 'n' is 1, and the DOW of the input date 'date_in' matches the
DOW specified by 'dow_index', then the routine will return the
input date as its result.
*/
#include "scdtl_2.h"
struct DATE_INFO Nth_DOW_before_date (int n, int dow_index, struct DATE_INFO *date_in)
{
int index, diff;
double jd;
struct DATE_INFO date;
date = make_date (0, 0, 0);
if (n < 1)
return (date);
if ( (dow_index < 0) || (dow_index > 6) )
return (date);
if ( (date_in->month < 1) || (date_in->month > 12) )
return (date);
jd = date_to_JD0 (date_in);
index = day_of_week_index_JD0 (jd);
diff = (dow_index - index);
|
|
|
|
|
|
|
|