SourcePro® API Reference Guide

Product Documentation:
   SourcePro
Documentation Home
List of all members | Public Member Functions

A basic, concrete time zone implementation of the abstract class RWZone, based on the Daylight Saving Time (DST) rules defined in struct RWDaylightRule. More...

#include <rw/tools/zone.h>

Inheritance diagram for RWZoneSimple:
RWZone

Public Member Functions

 RWZoneSimple (const RWDaylightRule *rule, long int stdoff, const RWCString &stdname, long int altoff, const RWCString &altname)
 
 RWZoneSimple (long int tzoff, const RWCString &tzname)
 
 RWZoneSimple (RWZone::StdZone zone, const RWDaylightRule *rule)
 
 RWZoneSimple (RWZone::StdZone zone, RWZone::DstRule=RWZone::NoAm)
 
 RWZoneSimple (const RWZoneSimple &zone)
 
 RWZoneSimple (RWZoneSimple &&zone)
 
virtual RWCString altZoneName () const
 
virtual int altZoneOffset () const
 
virtual bool daylightObserved () const
 
virtual void getBeginDaylight (struct tm *) const
 
virtual void getEndDaylight (struct tm *) const
 
virtual bool isDaylight (const struct tm *) const
 
RWZoneSimpleoperator= (const RWZoneSimple &)
 
RWZoneSimpleoperator= (RWZoneSimple &&zone)
 
void swap (RWZoneSimple &rhs)
 
virtual RWCString timeZoneName () const
 
virtual int timeZoneOffset () const
 
- Public Member Functions inherited from RWZone
virtual rwint64 fromTM (const struct tm *tmbuf) const
 
virtual RWCString name (const struct tm *tmbuf) const
 
virtual int offset (const struct tm *tmbuf) const
 
virtual void toTM (rwint64 msec, struct tm *tmbuf, int *tzOffset, RWCString *tzName) const
 

Additional Inherited Members

- Public Types inherited from RWZone
enum  DstRule { NoDST, NoAm, WeEu, OfficialEU }
 
enum  StdZone {
  NewZealand, CarolineIslands, MarianaIslands, Japan,
  China, Java, Kazakh, Pakistan,
  CaspianSea, Ukraine, Nile, Europe,
  Greenwich, Azores, Oscar, Greenland,
  Atlantic, USEastern, USCentral, USMountain,
  USPacific, Yukon, Hawaii, Bering
}
 
- Static Public Member Functions inherited from RWZone
static const RWDaylightRuledstRule (DstRule rule=NoAm)
 
static const RWZonelocal ()
 
static const RWZonelocal (const RWZone *zone)
 
static const RWZoneos ()
 
static const RWZonestandard ()
 
static const RWZonestandard (const RWZone *zone)
 
static const RWZoneutc ()
 

Detailed Description

RWZoneSimple is an implementation of the abstract interface defined by class RWZone. It implements a simple DST 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.

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.

Instances of RWZoneSimple may be constructed to represent other time zones, and may be installed globally using the RWZone static member function RWZone::local(const RWZone*).

Synopsis
#include <time.h>
#include <rw/zone.h>
Persistence
None
Example

To install US Central time 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

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

// last Sun in Apr to last in Oct:
const RWDaylightRule usRuleAuld =
{ 0, 0000, 1, { 3, 4, 0, 120 }, { 9, 4, 0, 120 } };
// first Sun in Apr to last in Oct
const RWDaylightRule usRule67 =
{ &usRuleAuld, 1967, 1, { 3, 0, 0, 120 }, { 9, 4, 0, 120 } };
// first Sun in Jan to last in Oct:
const RWDaylightRule usRule74 =
{ &usRule67, 1974, 1, { 0, 0, 0, 120 }, { 9, 4, 0, 120 } };
// last Sun in Feb to last in Oct
const RWDaylightRule usRule75 =
{ &usRule74, 1975, 1, { 1, 4, 0, 120 }, { 9, 4, 0, 120 } };
// last Sun in Apr to last in Oct
const RWDaylightRule usRule76 =
{ &usRule75, 1976, 1, { 3, 4, 0, 120 }, { 9, 4, 0, 120 } };
// first Sun in Apr to last in Oct
const RWDaylightRule usRuleLate =
{ &usRule76, 1987, 1, { 3, 0, 0, 120 }, { 9, 4, 0, 120 } };

And here are the rules for the RWZone::WeEu value:

// last Sun in March (2am) to last in September
static RWDaylightRule euRuleAuld =
{ 0, 0000, 1, { 2, 4, 0, 120 }, { 8, 4, 0, 120 } };
// last Sun in March (1am) to last in Oct
static RWDaylightRule euRuleLate =
{ &euRuleAuld, 1998, 1, { 2, 4, 0, 60 }, { 9, 4, 0, 60 } };

And here are the rules for the RWZone::OfficialEU value:

// Last Sun in March (2am) to last in Sept
static RWDaylightRule euOfficialRuleAuld =
{ 0, 0000, 1, { 2, 4, 0, 120 }, { 8, 4, 0, 120 } };
// Last Sun in March (2am) to last in Oct
static RWDaylightRule euOfficialRuleLate1996 =
{ &euOfficialRuleAuld, 1996, 1, { 2, 4, 0, 120 }, { 9, 4, 0, 180 } };

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.

Constructor & Destructor Documentation

RWZoneSimple::RWZoneSimple ( const RWDaylightRule rule,
long int  stdoff,
const RWCString stdname,
long int  altoff,
const RWCString altname 
)
inline

Constructs an RWZoneSimple instance in which DST is computed according to the provided rule. If rule is zero, DST is not observed.

Parameters
ruleThe DST rule
stdoffThe offset from GMT (in seconds, positive if west of 0 degrees longitude)
stdnameThe name of Standard time
altoffThe offset (typically equal to tzoff - 600) to define when DST is in effect
altnameAlternative name for the time zone when DST is in effect, for example, MDT for Mountain Daylight Time.
RWZoneSimple::RWZoneSimple ( long int  tzoff,
const RWCString tzname 
)

Constructs an RWZoneSimple instance in which DST is not observed. Argument tzoff is the offset from GMT (in seconds, positive if west of 0 degrees longitude) and tzname is the name of the zone.

RWZoneSimple::RWZoneSimple ( RWZone::StdZone  zone,
const RWDaylightRule rule 
)

Constructs an RWZoneSimple instance in which offsets and names are specified by the StdZone argument. DST is computed according to the rule argument, if non-zero; otherwise, DST is not observed.

RWZoneSimple::RWZoneSimple ( RWZone::StdZone  zone,
RWZone::DstRule  = RWZone::NoAm 
)

Constructs an RWZoneSimple instance using internal RWDaylightRule instances. This is the simplest interface to RWZoneSimple. The argument zone is the time zone for which an RWZoneSimple is to be constructed. The second argument defines the DST rule to follow. North America's DST rules are the default.

RWZoneSimple::RWZoneSimple ( const RWZoneSimple zone)

Copy constructor.

RWZoneSimple::RWZoneSimple ( RWZoneSimple &&  zone)

Move constructor. The constructed instance takes ownership of the data owned by zone.

Condition:
This method is available only on platforms with rvalue reference support.

Member Function Documentation

virtual RWCString RWZoneSimple::altZoneName ( ) const
virtual

Returns the name of the DST zone represented, such as "PDT". Note that the current date and time have no effect on the return value.

Implements RWZone.

virtual int RWZoneSimple::altZoneOffset ( ) const
virtual

Returns the number of seconds west of GMT for DST in this zone.

Implements RWZone.

virtual bool RWZoneSimple::daylightObserved ( ) const
virtual

Returns true if DST is observed for this zone.

Implements RWZone.

virtual void RWZoneSimple::getBeginDaylight ( struct tm *  tmbuf) const
virtual

Returns with the struct tm argument set to the local time that DST begins for the year specified by the tm_year field of tmbuf. If DST is not observed, the members of tmbuf are all set to a negative value. Note that in the southern hemisphere, DST ends at an earlier date than it begins.

Implements RWZone.

virtual void RWZoneSimple::getEndDaylight ( struct tm *  tmbuf) const
virtual

Returns with the struct tm argument set to the local time that DST ends for the year specified by the tm_year field of tmbuf. If DST is not observed, the members of tmbuf are all set to a negative value. Note that in the southern hemisphere, DST ends at an earlier date than it begins.

Implements RWZone.

virtual bool RWZoneSimple::isDaylight ( const struct tm *  tmbuf) const
virtual

Returns true if the time and date represented in the struct tm argument is in the range of DST for this zone. The elements of tmbuf must all be self-consistent; in particular, the tm_wday member must agree with the tm_year, tm_mon, and tm_day members.

Implements RWZone.

RWZoneSimple& RWZoneSimple::operator= ( const RWZoneSimple )

Assignment operator.

RWZoneSimple& RWZoneSimple::operator= ( RWZoneSimple &&  zone)

Move assignment. Self takes ownership of the data owned by zone.

Condition:
This method is available only on platforms with rvalue reference support.
void RWZoneSimple::swap ( RWZoneSimple rhs)

Swaps the data owned by self with the data owned by rhs.

virtual RWCString RWZoneSimple::timeZoneName ( ) const
virtual

Returns the name of the standard time zone represented, such as "PST". Note that the current date and time have no effect on the return value.

Implements RWZone.

virtual int RWZoneSimple::timeZoneOffset ( ) const
virtual

Returns the number of seconds west of GMT for standard time in this zone. The number is negative for zones east of Greenwich, England.

Implements RWZone.

Copyright © 2021 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.