Module: Essential Tools Module Group: Internationalization Classes
Does not inherit
altZoneName() altZoneOffset() daylightObserved() DstRule |
dstRule() getBeginDaylight() getEndDaylight() isDaylight() |
local() os() standard() StdZone |
timeZoneName() timeZoneOffset() utc() |
#include <time.h> #include <rw/zone.h> (abstract base class)
RWZone is an abstract base class. It defines an interface for time zone issues such as whether or not Daylight Saving Time is in use, the names and offsets from GMT (also known as UTC) for both standard and Daylight Saving Times, and the start and stop dates for Daylight Saving Time, if used. Note that because it is an abstract base class, there is no way to actually enforce these goals -- the description here is merely the model of how a class derived from RWZone should act.
Most programs interact with RWZone only by passing an RWZone reference to an RWDateTime, RWDate, or RWTime member function that expects one.
Daylight saving-time rules are volatile, often reflecting geographical and political changes. In some cases, the hard-coded table-driven struct RWDaylightRule does not accurately reflect the locale installed on your machine. RWZone::os() creates a new RWZoneSimple containing the daylight rule discovered from the underlying operating system. The onus of correctness for this DST rule is on the operating system itself.
In many cases, you may want more explicit control of the DST rule for the intended RWZoneSimple. If so, you can build a DST rule with arbitrary begin and end times (see the RWDaylightRule below), and provide it as a parameter to RWZoneSimple.
None
#include <rw/zone.h> #include <rw/zone.h> #include <rw/tools/datetime.h> int main () { RWDateTime now(RWDateTime::setCurrentTime); std::cout << now.asString("%x %X", RWLocale::global(), RWZone::local()) << std::endl; std::cout << now.asString("%x %X", RWLocale::global(), RWZone::utc()) << std::endl; return 0; }
To install the underlying system's DST rule as your global local time, use:
RWZone::local( &RWZone::os() );
Program output (as run on June 18, 2009):
06/18/09 13:43:46 06/18/09 17:43:46
enum DstRule {//supported Daylight Savings Time jurisdictions: NoDST, // Daylight Savings Time never observed NoAm, // North America (US, Canada) WeEu, // Much of Western Europe, excluding the UK OfficialEU // Official European Union DST rules. };
Used by the static member function dstRule(), described below, and by constructors for classes derived from RWZone, including RWZoneSimple.
enum StdZone { NewZealand = -12, CarolineIslands, MarianaIslands, Japan, China, Java, Kazakh, Pakistan, CaspianSea, Ukraine, Nile, Europe, Greenwich, Azores, Oscar, Greenland, Atlantic, USEastern, USCentral, USMountain, USPacific, Yukon, Hawaii, Bering };
Provided to name the standard time zones. Its values are intended to be passed to constructors of classes derived from RWZone.
virtual int timeZoneOffset() const = 0;
Returns the number of seconds west of GMT for standard time in this zone. The number is negative for zones east of Greenwich, England.
virtual int altZoneOffset() const = 0;
Returns the number of seconds west of GMT for Daylight Saving Time in this zone.
virtual bool daylightObserved() const = 0;
Returns true if Daylight Saving Time is observed for this zone.
virtual bool isDaylight(const struct tm* tspec) const = 0;
Returns true if the time and date represented in the struct tm argument is in the range of Daylight Saving Time for this zone. The elements of the tm argument must all be self-consistent; in particular, the tm_wday member must agree with the tm_year, tm_mon, and tm_day members.
virtual void getBeginDaylight(struct tm*) const = 0; virtual void getEndDaylight (struct tm*) const = 0;
Return with the struct tm argument set to the local time that Daylight Saving Time begins, or ends, for the year indicated by the tm_year member passed in. If Daylight Saving Time is not observed, the struct tm members are all set to a negative value. Note that in the southern hemisphere, Daylight Saving Time ends at an earlier date than it begins.
virtual RWCString timeZoneName() const = 0; virtual RWCString altZoneName() const = 0;
Return the name of, respectively, the standard and Daylight Saving Time zones represented, such as "PST" and "PDT". Note that the current date and time have no effect on the return values of these functions.
static const RWZone& local();
Returns a reference to an RWZone representing local time. By default this will be an instance of RWZoneSimple created with offsets and zone names from the operating system, with U.S. rules for Daylight Saving Time if observed. This is used as the default argument value for RWDate and RWTime functions that take an RWZone.
static const RWZone& os();
On the first call, determines the daylight saving rules for the years 1970 - 2038, from the underlying operating system. On subsequent calls, a cached copy is used. You can set the daylight saving rules for these years by instantiating RWZone::local( &RWZone::os() ).
static const RWZone& standard();
Returns a reference to an RWZone representing standard local time, with no Daylight Saving Time corrections. By default this is an instance of RWZoneSimple with offset and zone name from the operating system.
static const RWZone& utc();
Returns a reference to an RWZone representing GMT (UTC) universal time.
static const RWZone* local(const RWZone*); static const RWZone* standard(const RWZone*);
These functions allow the values returned by the other functions above to be set. Each returns the previous value.
static constRWDaylightRule* dstRule(DstRule rule = NoAm);
Returns one of the built-in Daylight Saving Time rules according to rule. Function dstRule() is provided for convenience in constructing RWZoneSimple instances for time zones in which common Daylight Saving Time rules are obeyed. RWZone has predefined names for these rules, defined under "Enumerations" for this class. If DstRule NoDST is given, then 0 is returned. The result of calling dstRule() is normally passed to the RWZoneSimple constructor.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.