|
|
|
|
|
|
|
begins the ecclesiastical year. Just as Easter is the central event of a cycle of days of observance, Christmas is the focus of a cycle, albeit one of less duration. The first clear references to the season in the West come in the latter half of the sixth century. |
|
|
|
|
|
|
|
|
This section illustrates two possible approaches to the generation of a date for Advent. The first approach attacks the problem directly, while the second illustrates the use of the utility functions. |
|
|
|
|
|
|
|
|
In the first example, the algorithm works by starting with 30 November and checking the day of the week on which it falls. If it falls on a Sunday, then 30 November is the closest Sunday, and the unmodified date is returned. Otherwise, the DOW index falls into one of two groups: |
|
|
|
|
|
|
|
|
The index is 1, 2, or 3, meaning Monday, Tuesday, or Wednesday. In this case 1, 2, or 3 is subtracted from the date. |
|
|
|
|
|
|
|
|
The index is 4, 5, or 6, meaning Thursday, Friday, or Saturday, in which case 3, 2, or 1 (respectively) is added to the date. |
|
|
|
|
|
|
|
|
This approach results in code like the following: |
|
|
|
|
|
|
|
|
#include "scdtl_2.h"
struct DATE_INFO advent (int year)
{
int index;
double jd;
struct DATE_INFO date;
date.year = year;
date.month = 11;
date.day = 30;
jd = date_to_JD0 (&date);
index = day_of_week_index_JD0 (jd);
if (index == 0)
return (date);
if ( (index > 0) && (index < 4) )
jd -= (double) index;
else
jd += (double) (7 - index);
date = JD0_to_date (jd);
return (date);
} |
|
|
|
|
|
|
|
|
The second approach uses the utility functions, producing shorter source code and a simpler maintenance situation, at the expense of some run time. |
|
|
|
|
|