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.
|
Base interface for ZoneSpecifier classes. More...
#include <ZoneSpecifier.h>
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 | |
ZoneSpecifier & | operator= (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) |
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.
|
inlineprotected |
Constructor.
Definition at line 95 of file ZoneSpecifier.h.
|
protectedpure virtual |
Return true if equal.
|
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.
|
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.
|
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.
|
inline |
Return the kTypeXxx of the current instance.
Definition at line 52 of file ZoneSpecifier.h.
|
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.
|
pure virtual |
Print a human-readable identifier.
Implemented in ace_time::ExtendedZoneSpecifier, ace_time::BasicZoneSpecifier, and ace_time::ManualZoneSpecifier.
|
static |
Indicate BasicZoneSpecifier.
Must not be TimeZone::kTypeFixed.
Definition at line 46 of file ZoneSpecifier.h.
|
static |
Indicate ExtendedZoneSpecifier.
Must not be TimeZone::kTypeFixed.
Definition at line 49 of file ZoneSpecifier.h.
|
static |
Indicate ManualZoneSpecifier.
Must not be TimeZone::kTypeFixed.
Definition at line 43 of file ZoneSpecifier.h.