|
|
Class Time supports the notion of Time as a repeating cycle of seven-day weeks by means of three `day-of-week' operations. These take arguments (or return results) which are integers in the range [0,6], where 0 represents Sunday, 1 represents Monday, and so on. You can use the enumeration type Time::Weekday when naming these numbers. The most fundamental of these functions tells which day of the week a given Time falls on. For example:
cout << Time(1988,Time::november,8).week_day() << endl;
prints 2, confirming that Election Day (as usual) falls on Tuesday in 1988.
Two other functions compute the Times of ``nearby'' weekdays. If we didn't know the date of Election Day in 1988, we could compute it using the `second Tuesday in November' rule. (The function make_string() is explained in the section, ``Conversion to and from strings''.)
Time t(1988,Time::october,31); cout << t.next(Time::tuesday) .next(Time::tuesday) .make_string("%D");
which prints:
11/08/88
Function previous() finds the time of the most recent specified weekday. For example, the date of the last Sunday in April would be:
Time(1988,Time::may,1).previous(Time::sunday);
Like the component extractors, each day-of-week operation comes in two forms: with and without the Place parameter.