Tools.h++ Manual

6-2 104011 Tandem Computers Incorporated
6
6.1 Example
This example prints out the date 6 January 1990 and then calculates and prints
the date of the previous Sunday, using the global locale:
Program output:
6-Jan-90, a Saturday
The previous Sunday is: 31-Dec-89
6.2 Constructors
An
RWDate
may be constructed in several ways. For example:
1. Construct a
RWDate
with the current date
1
:
RWDate d
;
2. Construct a
RWDate
for a given day of the year (1–365) and a given year
(e.g., 1989 or 89)
RWDate d1(24, 1990); // 1/24/1990
RWDate d2(24, 90); // 1/24/1990
1. Because the default constructor for
RWDate
fills in todays’s date, constructing a large array of
RWDate
may
be slow. If this is an issue, declare your arrays with a class derived from
RWDate
that provides a faster
constructor.
#include <rw/rwdate.h>
#include <rw/rstream.h>
main()
{
RWDate dd(6, "January", 1990);
cout << dd << ", a " << dd.weekDayName() << endl;
RWDate prev = dd.previous("Sunday");
cout << "The previous Sunday is: " << prev << endl;
return 0;
}