Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNo next file
Essential Tools Module Reference Guide


Module:  Essential Tools Module   Group:  Internationalization


Local Index



#include <time.h>
#include <rw/zone.h>
RWZoneSimple myZone(USCentral);


RWZoneSimple is an implementation of the abstract interface defined by class RWZone. It implements a simple Daylight Saving Time rule sufficient to represent all historical U.S. conventions and many European and Asian conventions. It is table-driven and depends on parameters given by the struct RWDaylightRule, which is discussed later in this class.

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.

Direct use of RWDaylightRule affords the most general interface to RWZoneSimple. However, a much simpler programmatic interface is offered, as illustrated by the examples below.

Three instances of RWZoneSimple are automatically constructed at program startup, to represent GMT, Standard, and local time. They are available via calls to the static member functions RWZone::utc(), RWZone::standard(), and RWZone::local(), respectively.

These member functions are set up according to the time zone facilities provided in the execution environment (typically defined by the environment variable TZ). By default, if DST is observed at all, then the local zone instance will use U.S. (RWZone::NoAm) Daylight Saving Time rules.

Note for developers outside North America: for some time zones this default will not be correct because these time zones rely on the C standard global variable _daylight. This variable is set whenever any alternate time zone rule is available, whether it represents Daylight Saving Time or not. Also the periods of history affected by Daylight Saving Time may be different in your time zone from those in North America, causing the North American rule to be erroneously invoked. The best way to ensure that these default time zones are correct is to construct an RWZoneSimple using an appropriate RWDaylightRule and initialize RWZone::local() and RWZone::std() with this value.

Other instances of RWZoneSimple may be constructed to represent other time zones, and may be installed globally using RWZone static member functions RWZone::local(const RWZone*) and RWZone::standard(const RWZone*).




To install US Central time as your global "local" time use:

To install the underlying operating system's Daylight Saving Time rule as your global "local" time use:

To install Hawaiian time (where Daylight Saving Time is not observed), use:

Likewise for Japan, use:

For France:

RWZone has predefined values for the RWZone::DstRule rules:


Daylight Savings Time never observed


North America (US, Canada)


Much of Western Europe, excluding the UK


Official European Union DST rules

Here are the rules used internally for the NoAm, WeEu, and OfficialEU values of RWZone::DstRule. First, here are the rules for the NoAm value:

And here are the rules for the WeEu value:

And here are the rules for the OfficialEU value:

Given these definitions,

is equivalent to the first example given above and repeated here:

Daylight Saving Time systems that cannot be represented with RWDaylightRule and RWZoneSimple must be modeled by deriving from RWZone and implementing its virtual functions.

For example, under Britain's Summer Time rules, alternate timekeeping begins the morning after the third Saturday in April, unless that is Easter (in which case it begins the week before) or unless the Council decides on some other time for that year. In some years Summer Time has been two hours ahead, or has extended through winter without a break. British Summer Time clearly deserves an RWZone class all its own.


RWZoneSimple(RWZone::StdZone zone, 
             RWZone::DstRule = RWZone::NoAm);
RWZoneSimple(const RWDaylightRule* rule,
             long tzoff,  const RWCString& tzname,
             long altoff, const RWCString& altname);
RWZoneSimple(long tzoff, const RWCString& tzname);
RWZoneSimple(RWZone::StdZone zone, 
             const RWDaylightRule* rule); 

struct RWDaylightRule

The RWDaylightRule struct passed to RWZoneSimple's constructor can be a single rule for all years or can be the head of a chain of rules going backwards in time.

RWDaylightRule is a struct with no constructors. It can be initialized with the syntax used in the Examples section above. The data members of this structure are as follows:

struct RWExport RWDaylightRule {
  RWDaylightRule const* next_;
  short firstYear_;
  char observed_;
  RWDaylightBoundary begin_; 
  RWDaylightBoundary end_;
RWDaylightRule const*

struct RWDaylight-Boundary

struct RWExport RWDaylightBoundary {
  // this struct uses <time.h> struct tm conventions:
  int month_;    // [0..11]
  int week_;     // [0..4], or -1
  int weekday_;  // [0..6], 0=Sunday; or, [1..31] if week_== -1
  int minute_;   // [0..1439]  (Usually 2 AM, = 120)

Previous fileTop of DocumentContentsIndex pageNo next file

©2004 Copyright Quovadx, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Quovadx, 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.