Time, Dates – HP Integrity NonStop J-Series User Manual
Page 240

Dates
Now suppose you are American and want to format a date in German, but don't want German to be
the default. Construct a German locale:
RWLocale& german = *new RWLocaleSnapshot("de"); //See footnote 1
You can format the same date for both local and German readers as follows:
cout << today << endl
<< today.asString('x', german) << endl;
See the definition of x in the entry for
RWLocale
in the Class Reference.
Would you like to read in a German date string? Again, the straightforward way is to call everything
explicitly:
RWCString str;
cout << "enter a date in German: " << flush;
str.readLine(cin);
today = RWDate(str, german);
if (today.isValid())
cout << today << endl;
Sometimes, however, you would prefer to use the extraction operator >>. Since the operator must
expect a German-formatted date, and know how to parse it, you pass this information along by
imbuing a stream with the German locale.
The following code snippet imbues the stream cin with the German locale, reads in and converts a
date string from German, and displays it in the local format:
german.imbue(cin);
cout << "enter a date in German: " << flush;
cin >> today; // read a German date!
if (today.isValid())
cout << today << endl;
Imbuing is useful when many values must be inserted or extracted according to a particular locale, or
when there is no way to pass a locale argument to the point where it will be needed. By using the
static member function RWLocale::of(ios&), your code can discover the locale imbued in a stream. If
the stream has not yet been imbued, of() returns the current global locale.
[29]
The interface defined by
RWLocale
handles more than dates. It can also convert times, numbers, and
monetary values to and from strings. Each has its complications. Time conversions are complicated
by the need to identify the time zone of the person who entered the time string, or the person who will
read it. The mishmash of daylight-saving time jurisdictions can magnify the difficulty. Numbers are
somewhat messy to format because their insertion and extraction operators (<< and >>) are already
defined by
representation for monetary values. Fortunately, none of these problems is overwhelming with
Tools.h++.