SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches

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 (const RWZoneSimple &zone)
 
 RWZoneSimple (long int tzoff, const RWCString &tzname)
 
 RWZoneSimple (RWZone::StdZone zone, const RWDaylightRule *rule)
 
 RWZoneSimple (RWZone::StdZone zone, RWZone::DstRule=RWZone::NoAm)
 
 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 <rw/zone.h>
#include <time.h>
A basic, concrete time zone implementation of the abstract class RWZone, based on the Daylight Saving...
Definition tools/zone.h:652
@ USCentral
Definition tools/zone.h:447
Persistence
None
Example

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

RWZoneSimple(const RWDaylightRule *rule, long int stdoff, const RWCString &stdname, long int altoff, const RWCString &altname)
Definition tools/zone.h:687
static const RWZone & local()

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

@ NoDST
Definition tools/zone.h:484
@ Hawaii
Definition tools/zone.h:467

Likewise for Japan, use:

@ Japan
Definition tools/zone.h:372

For France:

@ WeEu
Definition tools/zone.h:494
@ Europe
Definition tools/zone.h:412

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}};
Struct that defines daylight saving time rules.
Definition tools/zone.h:79

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,

@ NoAm
Definition tools/zone.h:489

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() [1/6]

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() [2/6]

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() [3/6]

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() [4/6]

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() [5/6]

RWZoneSimple::RWZoneSimple ( const RWZoneSimple & zone)

Copy constructor.

◆ RWZoneSimple() [6/6]

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

◆ altZoneName()

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.

◆ altZoneOffset()

virtual int RWZoneSimple::altZoneOffset ( ) const
virtual

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

Implements RWZone.

◆ daylightObserved()

virtual bool RWZoneSimple::daylightObserved ( ) const
virtual

Returns true if DST is observed for this zone.

Implements RWZone.

◆ getBeginDaylight()

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

Sets the struct tm tmbuf to the local time representing the first transition to daylight saving time (DST) for the year specified by the tm_year field of tmbuf. If a daylight transition does not occur in the specified year, 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.

◆ getEndDaylight()

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

Sets the struct tm tmbuf to the local time representing the first transition away from daylight saving time (DST) for the year specified by the tm_year field of tmbuf. If a daylight transition does not occur in the specified year, 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.

◆ isDaylight()

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.

◆ operator=() [1/2]

RWZoneSimple & RWZoneSimple::operator= ( const RWZoneSimple & )

Assignment operator.

◆ operator=() [2/2]

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.

◆ swap()

void RWZoneSimple::swap ( RWZoneSimple & rhs)

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

◆ timeZoneName()

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.

◆ timeZoneOffset()

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 © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.