Tools.h++ Manual
104011 Tandem Computers Incorporated 4-7
4
The flight is about seven hours long, each way:
RWTime arriveParis (leaveNewYork + long(7 * 3600));
RWTime arriveNewYork(leaveParis + long(7 * 3600));
Let’s display the Paris arrival time and date in French, and the New York
arrival time and date according to local convention:
This works even though your flight crosses several time zones and arrives on a
different day than it departed. Furthermore, on the day of the return trip (in
the following year), France has already begun observing Daylight Savings
Time, but the U.S. has not. None of these details is visible in the example code
above—they are handled silently and invisibly by
RWTime
and
RWZone
.
All this is easy for places that follow those DST rules Tools.h++ has built in.
(Thus far, these are North America, Western Europe, and “noDST”.) What
about places that follow other rules, such as Argentina, where spring begins in
September and summer ends in March?
RWZoneSimple
is table-driven; if the
rule is simple enough, you can construct your own table (of type
RWDaylightRule
) and specify it as you construct an
RWZoneSimple
. For
example, imagine that DST begins at 2 AM on the last Sunday in September,
and ends the first Sunday in March. Simply create a static instance of
RWDaylightRule
:
static RWDaylightRule sudAmerica =
{ 0, 0, TRUE, {8, 4, 0, 120}, {2, 0, 0, 120}};
(See the RWZoneSimple documentation, and <rw/zone.h>, for details on what
the numbers mean.) Then construct an RWZone object:
RWZoneSimple ciudadSud( RWZone::Atlantic, &sudAmerica );
Now you can use
ciudadSud
identically as
paris
or
newYork
above.
But what about places where the DST rules are too complicated to describe
with a simple table, such as Great Britain? There, DST begins on the morning
after the third Saturday in April, unless that is Easter, in which case it begins
RWLocaleSnapshot french("fr"); // or "fr_FR"
cout << "Arrive' au Paris a' "
<< arriveParis.asString('c', parisZone, french)
<< ", heure local." << endl;
cout << "Arrive in New York at "
<< arriveNewYork.asString('c', newYorkZone)
<< ", local time." << endl;