AceTime  0.3
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock that can synchronize from an NTP server or an RTC chip.
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
ace_time::ZoneSpecifier Class Referenceabstract

Base interface for ZoneSpecifier classes. More...

#include <ZoneSpecifier.h>

Inheritance diagram for ace_time::ZoneSpecifier:
Inheritance graph
[legend]

Public Member Functions

uint8_t getType () const
 Return the kTypeXxx of the current instance. More...
 
virtual TimeOffset getUtcOffset (acetime_t epochSeconds) const =0
 Return the total UTC offset at epochSeconds, including DST offset. More...
 
virtual TimeOffset getDeltaOffset (acetime_t epochSeconds) const =0
 Return the DST delta offset at epochSeconds. More...
 
virtual const char * getAbbrev (acetime_t epochSeconds) const =0
 Return the time zone abbreviation at epochSeconds. More...
 
virtual OffsetDateTime getOffsetDateTime (const LocalDateTime &ldt) const =0
 Return the best estimate of the OffsetDateTime at the given LocalDateTime for the timezone of the current ZoneSpecifier. More...
 
virtual void printTo (Print &printer) const =0
 Print a human-readable identifier. More...
 

Static Public Attributes

static const uint8_t kTypeManual = 1
 Indicate ManualZoneSpecifier. More...
 
static const uint8_t kTypeBasic = 2
 Indicate BasicZoneSpecifier. More...
 
static const uint8_t kTypeExtended = 3
 Indicate ExtendedZoneSpecifier. More...
 

Protected Member Functions

 ZoneSpecifier (const ZoneSpecifier &)=default
 
ZoneSpecifieroperator= (const ZoneSpecifier &)=default
 
 ZoneSpecifier (uint8_t type)
 Constructor. More...
 
virtual bool equals (const ZoneSpecifier &other) const =0
 Return true if equal. More...
 

Protected Attributes

uint8_t mType
 

Friends

bool operator== (const ZoneSpecifier &a, const ZoneSpecifier &b)
 

Detailed Description

Base interface for ZoneSpecifier classes.

There were 2 options for implmenting the various concrete implementations of ZoneSpecifiers:

1) Implement only a single getType() method to distinguish the different runtime types of the object. Then use this type information in the TimeZone class to downcast the ZoneSpecifier pointer to the correct subclass, and call the correct methods.

2) Fully implement a polymorphic class hierarchy, lifting various common methods (getUtcOffset(), getDeltaOffset(), getAbbrev()) into this interface as virtual methods, then add a virtual equals() method to implement the operator==().

When I had only 2 ZoneSpecifier implementations (BasicZoneSpecifier and ManualZoneSpecifier), Option 1 (using a single getType() and downcasting) seemed to smaller program sizes, by 200-300 bytes. The problem with this design is that the code for both subclasses would be compiled into the program, even if the application used only one of the subclasses. When a 3rd ZoneSpecifier subclass was added (ExtendedZoneSpecifier), the overhead became untenable. So I switched to Option 2, using a fully polymorphic class hierarchy, adding 3-4 virtual methods. When a program uses only a single subclass, only that particular subclass is included into the program. Unfortunately, this comes at the cost of forcing programs to use the virtual dispatch at runtime for some of the often-used methods.

Definition at line 40 of file ZoneSpecifier.h.

Constructor & Destructor Documentation

◆ ZoneSpecifier()

ace_time::ZoneSpecifier::ZoneSpecifier ( uint8_t  type)
inlineprotected

Constructor.

Definition at line 95 of file ZoneSpecifier.h.

Member Function Documentation

◆ equals()

virtual bool ace_time::ZoneSpecifier::equals ( const ZoneSpecifier other) const
protectedpure virtual

Return true if equal.

◆ getAbbrev()

virtual const char* ace_time::ZoneSpecifier::getAbbrev ( acetime_t  epochSeconds) const
pure virtual

Return the time zone abbreviation at epochSeconds.

This is an experimental method that has not been tested thoroughly. Use with caution. Returns an empty string ("") if an error occurs.

Implemented in ace_time::ExtendedZoneSpecifier, ace_time::BasicZoneSpecifier, and ace_time::ManualZoneSpecifier.

◆ getDeltaOffset()

virtual TimeOffset ace_time::ZoneSpecifier::getDeltaOffset ( acetime_t  epochSeconds) const
pure virtual

Return the DST delta offset at epochSeconds.

This is an experimental method that has not been tested thoroughly. Use with caution. Returns TimeOffset::forError() if an error occurs.

Implemented in ace_time::ExtendedZoneSpecifier, ace_time::BasicZoneSpecifier, and ace_time::ManualZoneSpecifier.

◆ getOffsetDateTime()

virtual OffsetDateTime ace_time::ZoneSpecifier::getOffsetDateTime ( const LocalDateTime ldt) const
pure virtual

Return the best estimate of the OffsetDateTime at the given LocalDateTime for the timezone of the current ZoneSpecifier.

Returns OffsetDateTime::forError() if an error occurs, for example, if the LocalDateTime is outside of the support date range of the underlying ZoneInfo files.

Implemented in ace_time::ExtendedZoneSpecifier, ace_time::BasicZoneSpecifier, and ace_time::ManualZoneSpecifier.

◆ getType()

uint8_t ace_time::ZoneSpecifier::getType ( ) const
inline

Return the kTypeXxx of the current instance.

Definition at line 52 of file ZoneSpecifier.h.

◆ getUtcOffset()

virtual TimeOffset ace_time::ZoneSpecifier::getUtcOffset ( acetime_t  epochSeconds) const
pure virtual

Return the total UTC offset at epochSeconds, including DST offset.

Returns TimeOffset::forError() if an error occurs.

Implemented in ace_time::ExtendedZoneSpecifier, ace_time::BasicZoneSpecifier, and ace_time::ManualZoneSpecifier.

◆ printTo()

virtual void ace_time::ZoneSpecifier::printTo ( Print &  printer) const
pure virtual

Print a human-readable identifier.

Implemented in ace_time::ExtendedZoneSpecifier, ace_time::BasicZoneSpecifier, and ace_time::ManualZoneSpecifier.

Member Data Documentation

◆ kTypeBasic

const uint8_t ace_time::ZoneSpecifier::kTypeBasic = 2
static

Indicate BasicZoneSpecifier.

Must not be TimeZone::kTypeFixed.

Definition at line 46 of file ZoneSpecifier.h.

◆ kTypeExtended

const uint8_t ace_time::ZoneSpecifier::kTypeExtended = 3
static

Indicate ExtendedZoneSpecifier.

Must not be TimeZone::kTypeFixed.

Definition at line 49 of file ZoneSpecifier.h.

◆ kTypeManual

const uint8_t ace_time::ZoneSpecifier::kTypeManual = 1
static

Indicate ManualZoneSpecifier.

Must not be TimeZone::kTypeFixed.

Definition at line 43 of file ZoneSpecifier.h.


The documentation for this class was generated from the following file: