Tools.h++ Manual
104011 Tandem Computers Incorporated 6-3
6
3. Construct a
RWDate
for a given day of the month (1–31), month number
(1–12) and year:
RWDate d(10, 3, 90); // 3/10/1990
4. Construct a
RWDate
from a
RWTime
:
RWTime t; // Current time.
RWDate d(t);
In addition, you can construct a date using locale-specific strings. If you do
nothing, a “default locale” will be used. This locale uses US conventions and
names:
RWDate d1(10, "June", 90); // 6/10/1990
RWDate d2(10, "JUN", 90); // 6/10/1990
Suppose you wished to use French month names and your system supported a
French locale. Here’s how you might do it:
Here’s a line-by-line description:
#include <rw/rwdate.h>
#include <rw/rstream.h>
#include <rw/locale.h>
#include <rw/cstring.h>
#include <assert.h>
main()
{
RWLocaleSnapshot french("fr"); // or "fr_FR" // 1
RWDate d(10, "Juin", 90, french); // OK // 2
assert(RWDate(10, "Juin", 90).isValid() == FALSE);// 3
assert(RWDate(10, "June", 90, french).isValid() == FALSE);// 4
cout << d << endl; // 5
cout << d.asString() << endl; // 6
cout << d.asString('x', french) << endl; // 7
return 0;
}