|
|
|
|
|
|
|
6.2.1.2.5 DOW_closest_to_date () |
|
|
|
|
|
|
|
|
Returns the date corresponding to the day of the week closest to a given date. For example, this routine (Listing 6.5) returns the date for the Sunday closest to 30 NOV 1994 (the definition of Advent Sunday). |
|
|
|
|
| Listing 6.4 | |
|
|
|
|
/*
If diff = 0 below, the input date is the 1st DOW already, no adjustment
is required. The 'diff' is the adjustment from the input date
required to get to the first DOW matching the 'dow_index' given.
*/
if (diff < 0)
jd += (double) (diff);
else
{
if (diff > 0)
jd += (double) (diff - 7);
}
/* n < 1 has already been eliminated as an error, so n >= 1.
*/
jd -= (double) ((n - 1) * 7);
date = JD0_to_date (jd);
return (date);
}
|
|
|
|
|
|
|
| Listing 6.5 DOW_closest_to_date () | |
|
|
|
|
/* dowclose.c
+-------------------------------------------+
| Copyright (C) 1995 by Lance W. Latham. |
| All rights reserved. |
+-------------------------------------------+
Returns the date corresponding to the day of the week closest to
a given date. E.g., this routine returns the date for "the Sunday
closest to 30 NOV 1994" (the definition of Advent Sunday).
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. 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 day of the week (DOW) closest to the
date given. In the event of an error, the routine returns
a date consisting of the year, month and day set to zero.
|
|
|
|
|
|
|
|