|
|
|
|
|
|
|
6.2.1.2.4 Nth_DOW_before_date () |
|
|
|
|
|
|
|
|
Returns the date corresponding to the Nth day of the week on or before a given date. That is, this routine (Listing 6.4) returns the date for the fourth Thursday on or before 02 March 1994 or the first Tuesday on or before Christmas 1866. |
|
|
|
|
| Listing 6.3 | |
|
|
|
|
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);
/*
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) (7 + diff);
else
{
if (diff > 0)
jd += (double) (diff);
}
/*
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.4 Nth_DOW_before_date () | |
|
|
|
|
/* nthdowbe.c
+-------------------------------------------+
| Copyright (C) 1995 by Lance W. Latham. |
| All rights reserved. |
+-------------------------------------------+
Returns the date corresponding to the Nth day of the week, on or before a given
date. I.e., this routine returns the date for "the fourth Thursday on or before 02
March 1994", or "the first Tuesday on or before Christmas of 1866".
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.
|
|
|
|
|
|
|
|