AceTime  1.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::ZoneProcessor Class Referenceabstract

Base interface for ZoneProcessor classes. More...

#include <ZoneProcessor.h>

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

Public Member Functions

uint8_t getType () const
 Return the kTypeXxx of the current instance.
 
virtual const void * getZoneInfo () const =0
 Return the opaque zoneInfo.
 
virtual uint32_t getZoneId () const =0
 Return the unique stable zoneId.
 
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 ZoneProcessor. More...
 
virtual void printTo (Print &printer) const =0
 Print a human-readable identifier (e.g. More...
 
virtual void printShortTo (Print &printer) const =0
 Print a short human-readable identifier (e.g. More...
 

Static Public Attributes

static const uint8_t kTypeBasic = 2
 Indicate BasicZoneProcessor. More...
 
static const uint8_t kTypeExtended = 3
 Indicate ExtendedZoneProcessor. More...
 

Protected Member Functions

 ZoneProcessor (const ZoneProcessor &)=delete
 
ZoneProcessoroperator= (const ZoneProcessor &)=delete
 
 ZoneProcessor (uint8_t type)
 Constructor.
 
virtual bool equals (const ZoneProcessor &other) const =0
 Return true if equal.
 
virtual void setZoneInfo (const void *zoneInfo)=0
 Set the opaque zoneInfo.
 

Protected Attributes

uint8_t mType
 

Friends

class TimeZone
 
template<uint8_t SIZE, uint8_t TYPE, typename ZS , typename ZI , typename ZIB >
class ZoneProcessorCacheImpl
 
bool operator== (const ZoneProcessor &a, const ZoneProcessor &b)
 

Detailed Description

Base interface for ZoneProcessor classes.

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

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 ZoneProcessor 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==().

The problem with Option 1 is that the code for both subclasses would be compiled into the program, even if the application used only one of the subclasses. Instead I use 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 45 of file ZoneProcessor.h.

Member Function Documentation

◆ getAbbrev()

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

Return the time zone abbreviation at epochSeconds.

Returns an empty string ("") if an error occurs. The returned pointer points to a char buffer that could get overriden by subsequent method calls to this object. The pointer must not be stored permanently, it should be used as soon as possible (e.g. printed out).

This is an experimental method that has not been tested thoroughly. Use with caution.

Implemented in ace_time::ExtendedZoneProcessor, and ace_time::BasicZoneProcessor.

◆ getDeltaOffset()

virtual TimeOffset ace_time::ZoneProcessor::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::ExtendedZoneProcessor, and ace_time::BasicZoneProcessor.

◆ getOffsetDateTime()

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

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

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::ExtendedZoneProcessor, and ace_time::BasicZoneProcessor.

◆ getUtcOffset()

virtual TimeOffset ace_time::ZoneProcessor::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::ExtendedZoneProcessor, and ace_time::BasicZoneProcessor.

◆ printShortTo()

virtual void ace_time::ZoneProcessor::printShortTo ( Print &  printer) const
pure virtual

Print a short human-readable identifier (e.g.

"Los_Angeles")

Implemented in ace_time::ExtendedZoneProcessor, and ace_time::BasicZoneProcessor.

◆ printTo()

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

Print a human-readable identifier (e.g.

"America/Los_Angeles").

Implemented in ace_time::ExtendedZoneProcessor, and ace_time::BasicZoneProcessor.

Member Data Documentation

◆ kTypeBasic

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

Indicate BasicZoneProcessor.

Must not be TimeZone::kTypeError (0) or TimeZone::kTypeManual (1).

Definition at line 51 of file ZoneProcessor.h.

◆ kTypeExtended

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

Indicate ExtendedZoneProcessor.

Must not be TimeZone::kTypeError (0) or TimeZone::kTypeManual (1).

Definition at line 57 of file ZoneProcessor.h.


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