AceTime  0.1
Date and time classes for Arduino that supports the TZ DAtabase, and a system clock synchronized 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 TimeOffset getUtcOffsetForDateTime (const LocalDateTime &ldt) const =0
 Return the UTC offset matching the given the date/time components. 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 differing 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 the program to use a virtual dispatch for some of the often-used methods.

Definition at line 39 of file ZoneSpecifier.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 84 of file ZoneSpecifier.h.

Member Function Documentation

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

Return true if equal.

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.

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

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.

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

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

Return the kTypeXxx of the current instance.

Definition at line 51 of file ZoneSpecifier.h.

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

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

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

virtual TimeOffset ace_time::ZoneSpecifier::getUtcOffsetForDateTime ( const LocalDateTime ldt) const
pure virtual

Return the UTC offset matching the given the date/time components.

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

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

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

Indicate BasicZoneSpecifier.

Definition at line 45 of file ZoneSpecifier.h.

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

Indicate ExtendedZoneSpecifier.

Definition at line 48 of file ZoneSpecifier.h.

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

Indicate ManualZoneSpecifier.

Definition at line 42 of file ZoneSpecifier.h.


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