Tools.h++ Manual

4-8 104011 Tandem Computers Incorporated
4
the week prior! For such jurisdictions you might best use Standard time,
properly labeled: they are probably used to it. If that just won’t do, you can
derive from
RWZone
and implement its interface for Britain alone. This is
much easier than trying to make something general enough to handle all
possibilities including Britain, and it’s smaller and faster besides.
The remaining problem is that there is no standard way to discover what DST
rules are in force for any particular place. In this the Standard C Library is no
help. Often, however, you can get the user in question to provide the
necessary information. One manifestation of this problem is that the local wall
clock time
RWZone
instance is constructed to use North American DST rules, if
DST is observed at all. If the user is not in North America, the default local
time zone probably performs DST conversions wrong, and you must replace it.
For example, for a user in Paris you could say:
RWZone::local(new RWZoneSimple(RWZone::Europe, RWZone::WeEu));
If you look closely into
<rw/locale.h>
, you will find that
RWDate
and
RWTime
are never mentioned. Instead,
RWLocale
operates on the Standard C
Library type struct tm.
RWDate
and
RWTime
both provide conversions to this
type. In some cases you may find using it directly is preferable to using
RWTime::asString()
.
For example, suppose you must write out a time string containing only hours
and minutes (e.g.
12:33
). The standard formats defined for
strftime()
(and
implemented by
RWLocale
as well) don’t include that option, but you can fake
it. Here’s one way:
RWTime now = RWTime::now();
cout << now.hour() << “:” << now.minute() << endl;
Without using various manipulators, this might produce a string like "
9:5
".
Here’s another way:
RWTime now = RWTime::now();
cout << now.asString(‘H’) << “:” << now.asString(‘M’) << endl;
This produces "
09:05
".