AceTime  1.0
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.
ZoneProcessor.h
1 /*
2  * MIT License
3  * Copyright (c) 2019 Brian T. Park
4  */
5 
6 #ifndef ACE_TIME_ZONE_PROCESSOR_H
7 #define ACE_TIME_ZONE_PROCESSOR_H
8 
9 #include "common/common.h"
10 #include "TimeOffset.h"
11 #include "OffsetDateTime.h"
12 
13 class Print;
14 
15 namespace ace_time {
16 
17 template<uint8_t SIZE, uint8_t TYPE, typename ZS, typename ZI, typename ZIB>
18 class ZoneProcessorCacheImpl;
19 
20 class LocalDateTime;
21 class TimeZone;
22 
46  public:
51  static const uint8_t kTypeBasic = 2;
52 
57  static const uint8_t kTypeExtended = 3;
58 
60  uint8_t getType() const { return mType; }
61 
63  virtual const void* getZoneInfo() const = 0;
64 
66  virtual uint32_t getZoneId() const = 0;
67 
72  virtual TimeOffset getUtcOffset(acetime_t epochSeconds) const = 0;
73 
79  virtual TimeOffset getDeltaOffset(acetime_t epochSeconds) const = 0;
80 
91  virtual const char* getAbbrev(acetime_t epochSeconds) const = 0;
92 
101  const = 0;
102 
104  virtual void printTo(Print& printer) const = 0;
105 
107  virtual void printShortTo(Print& printer) const = 0;
108 
109  protected:
110  friend bool operator==(const ZoneProcessor& a, const ZoneProcessor& b);
111 
112  friend class TimeZone; // setZoneInfo()
113 
114  template<uint8_t SIZE, uint8_t TYPE, typename ZS, typename ZI, typename ZIB>
115  friend class ZoneProcessorCacheImpl; // setZoneInfo()
116 
117  // Disable copy constructor and assignment operator.
118  ZoneProcessor(const ZoneProcessor&) = delete;
119  ZoneProcessor& operator=(const ZoneProcessor&) = delete;
120 
122  ZoneProcessor(uint8_t type):
123  mType(type) {}
124 
126  virtual bool equals(const ZoneProcessor& other) const = 0;
127 
129  virtual void setZoneInfo(const void* zoneInfo) = 0;
130 
131  uint8_t mType;
132 };
133 
134 inline bool operator==(const ZoneProcessor& a, const ZoneProcessor& b) {
135  if (a.mType != b.mType) return false;
136  return a.equals(b);
137 }
138 
139 inline bool operator!=(const ZoneProcessor& a, const ZoneProcessor& b) {
140  return ! (a == b);
141 }
142 
143 }
144 
145 #endif
Base interface for ZoneProcessor classes.
Definition: ZoneProcessor.h:45
virtual TimeOffset getDeltaOffset(acetime_t epochSeconds) const =0
Return the DST delta offset at epochSeconds.
A cache of ZoneProcessors that provides a ZoneProcessor to the TimeZone upon request.
uint8_t getType() const
Return the kTypeXxx of the current instance.
Definition: ZoneProcessor.h:60
static const uint8_t kTypeExtended
Indicate ExtendedZoneProcessor.
Definition: ZoneProcessor.h:57
virtual const void * getZoneInfo() const =0
Return the opaque zoneInfo.
virtual bool equals(const ZoneProcessor &other) const =0
Return true if equal.
virtual void printShortTo(Print &printer) const =0
Print a short human-readable identifier (e.g.
virtual TimeOffset getUtcOffset(acetime_t epochSeconds) const =0
Return the total UTC offset at epochSeconds, including DST offset.
virtual void setZoneInfo(const void *zoneInfo)=0
Set the opaque zoneInfo.
virtual const char * getAbbrev(acetime_t epochSeconds) const =0
Return the time zone abbreviation at epochSeconds.
virtual void printTo(Print &printer) const =0
Print a human-readable identifier (e.g.
virtual uint32_t getZoneId() const =0
Return the unique stable zoneId.
The date (year, month, day), time (hour, minute, second) and offset from UTC (timeOffset).
A thin wrapper that represents a time offset from a reference point, usually 00:00 at UTC...
Definition: TimeOffset.h:56
Class that describes a time zone.
Definition: TimeZone.h:82
ZoneProcessor(uint8_t type)
Constructor.
static const uint8_t kTypeBasic
Indicate BasicZoneProcessor.
Definition: ZoneProcessor.h:51
virtual OffsetDateTime getOffsetDateTime(const LocalDateTime &ldt) const =0
Return the best estimate of the OffsetDateTime at the given LocalDateTime for the timezone of the cur...
Class that holds the date-time as the components (year, month, day, hour, minute, second) without reg...
Definition: LocalDateTime.h:27