AceTime  0.7
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 
86  virtual const char* getAbbrev(acetime_t epochSeconds) const = 0;
87 
96  const = 0;
97 
99  virtual void printTo(Print& printer) const = 0;
100 
102  virtual void printShortTo(Print& printer) const = 0;
103 
104  protected:
105  friend bool operator==(const ZoneProcessor& a, const ZoneProcessor& b);
106 
107  friend class TimeZone; // setZoneInfo()
108 
109  template<uint8_t SIZE, uint8_t TYPE, typename ZS, typename ZI, typename ZIB>
110  friend class ZoneProcessorCacheImpl; // setZoneInfo()
111 
112  // Disable copy constructor and assignment operator.
113  ZoneProcessor(const ZoneProcessor&) = delete;
114  ZoneProcessor& operator=(const ZoneProcessor&) = delete;
115 
117  ZoneProcessor(uint8_t type):
118  mType(type) {}
119 
121  virtual bool equals(const ZoneProcessor& other) const = 0;
122 
124  virtual void setZoneInfo(const void* zoneInfo) = 0;
125 
126  uint8_t mType;
127 };
128 
129 inline bool operator==(const ZoneProcessor& a, const ZoneProcessor& b) {
130  if (a.mType != b.mType) return false;
131  return a.equals(b);
132 }
133 
134 inline bool operator!=(const ZoneProcessor& a, const ZoneProcessor& b) {
135  return ! (a == b);
136 }
137 
138 }
139 
140 #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:61
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