Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Hydra Core Library Reference Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

rwsf::TimeZoneSimple

Group:  General


rwsf::TimeZoneSimple rwsf::TimeZone

Local Index

Members

Header File

#include <rwsf/core/TimeZone.h>

Description

rwsf::TimeZoneSimple is an implementation of the abstract interface defined by class rwsf::TimeZone. 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 DaylightRule, 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 DaylightRule does not accurately reflect the locale installed on your machine. TimeZone::os() creates a new rwsf::TimeZoneSimple 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 rwsf::TimeZoneSimple. If so, you can build a DST rule with arbitrary begin and end times (see the DaylightRule below), and provide it as a parameter to rwsf::TimeZoneSimple.

Direct use of DaylightRule affords the most general interface to rwsf::TimeZoneSimple. However, a much simpler programmatic interface is offered, as illustrated by the examples below.

Three instances of rwsf::TimeZoneSimple are automatically constructed at program startup, to represent GMT, Standard, and local time. They are available via calls to the static member functions TimeZone::utc(), TimeZone::standard(), and TimeZone::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. (TimeZone::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 rwsf::TimeZoneSimple using an appropriate DaylightRule and initialize TimeZone::local() and TimeZone::std() with this value.

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

Examples

To install U.S. 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:

rwsf::TimeZone has predefined values for the rwsf::TimeZone::DstRule rules:

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

Here are the rules used internally for the NoAm, WeEu, and OfficialEU values of rwsf::TimeZone::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 DaylightRule and rwsf::TimeZoneSimple must be modeled by deriving from rwsf::TimeZone 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 rwsf::TimeZone class all its own.

Constructors

TimeZoneSimple(StdZone zone, 
    DstRule = NoAm);
TimeZoneSimple(const DaylightRule* rule,
    long tzoff,  const std::string& tz_name,
    long altoff, const std::string& altname);
TimeZoneSimple(long tzoff, const std::string& tz_name);
TimeZoneSimple(StdZone zone, 
    const DaylightRule* rule); 

struct DaylightRule

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

DaylightRule 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 DaylightRule {
  DaylightRule const* next_;
  short firstYear_;
  char observed_;
  DaylightBoundary begin_; 
  DaylightBoundary end_;
}


DaylightRule const*
next_;
short
firstYear_;
char
observed_;
DaylightBoundary
begin_;
DaylightBoundary
end_;

struct Daylight-Boundary

struct DaylightBoundary {

int
month_;
int
week_;
int
weekday_;
int
minute_;


Previous fileTop of DocumentContentsIndex pageNext file

©2004-2007 Copyright Quovadx, Inc. All Rights Reserved.
Quovadx and Rogue Wave are registered trademarks and HydraSDO is a trademark 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.