Time – HP Integrity NonStop J-Series User Manual
Page 241

Time
Let us first consider the time zone problem. We can easily see that there is no simple relationship
between time zones and locales. All of Switzerland shares a single time zone, including
daylight-saving time (DST) rules, but has four official languages: French, German, Italian, and
Romansch. On the other hand, Hawaii and New York share a common language, but occupy time
zones five hours apart_sometimes six hours apart, because Hawaii does not observe DST.
Furthermore, time zone formulas have little to do with cultural formatting preferences. For these
reasons, Tools.h++ uses a separate time zone object, rather than letting
RWLocale
subsume time
zone responsibilities.
In Tools.h++, the class
RWZone
encapsulates knowledge about time zones. It is an abstract class,
with an interface implemented in the class
RWZoneSimple
. Three instances of RWZoneSimple are
constructed at startup to represent local wall clock time, local Standard time, and Universal time
(GMT). Local wall clock time includes any DST in use. Whenever you convert an absolute time to or
from a string, as in the class
RWTime
, an instance of RWZone is involved. By default, the local time
is assumed, but you can pass a reference to any RWZone instance.
It's time for some examples! Imagine you had scheduled a trip from New York to Paris. You were to
leave New York on December 20, 1993, at 11:00 p.m., and return on March 30, 1994, leaving Paris at
5:00 a.m., Paris time. What will the clocks show at your destination when you arrive?
First, let's construct the time zones and the departure times:
RWZoneSimple newYorkZone(RWZone::USEastern, RWZone::NoAm);
RWZoneSimple parisZone (RWZone::Europe, RWZone::WeEu);
RWTime leaveNewYork(RWDate(20, 12, 1993), 23,00,00, newYorkZone);
RWTime leaveParis (RWDate(30, 3, 1994), 05,00,00, parisZone);
The flight is about seven hours long each way, so:
RWTime arriveParis (leaveNewYork + long(7 * 3600));
RWTime arriveNewYork(leaveParis + long(7 * 3600));
Now let's display the arrival times and dates according to their respective local conventions, French
in Paris and American English in New York:
RWLocaleSnapshot french("fr"); // or vendor specific
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;
The code works even though your flight crosses several time zones and arrives on a different day than
it departed; even though, on the day of the return trip in the following year, France has already begun
observing DST, 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 Tools.h++ built-in DST rules for North America, Western