AceTime  2.1.0
Date and time classes for Arduino that support timezones from the TZ Database.
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 "internal/common.h" // kAbbrevSize
11 #include "TimeOffset.h"
12 #include "OffsetDateTime.h"
13 
14 class Print;
15 
16 namespace ace_time {
17 
18 class LocalDateTime;
19 
25 class FindResult {
26  public:
27  static const uint8_t kTypeNotFound = 0;
28  static const uint8_t kTypeExact = 1;
29  static const uint8_t kTypeGap = 2;
30  static const uint8_t kTypeOverlap = 3;
31 
67  uint8_t type = kTypeNotFound;
68 
78  uint8_t fold = 0;
79 
81  int16_t stdOffsetMinutes = 0;
82 
84  int16_t dstOffsetMinutes = 0;
85 
97  int16_t reqStdOffsetMinutes = 0;
98 
110  int16_t reqDstOffsetMinutes = 0;
111 
117  const char* abbrev = "";
118 };
119 
143  public:
145  uint8_t getType() const { return mType; }
146 
151  void resetTransitionCache() { mIsFilled = false; }
152 
154  virtual bool isLink() const = 0;
155 
157  virtual uint32_t getZoneId() const = 0;
158 
161  const LocalDateTime& ldt) const = 0;
162 
165  acetime_t epochSeconds) const = 0;
166 
172  virtual void printNameTo(Print& printer) const = 0;
173 
180  virtual void printShortNameTo(Print& printer) const = 0;
181 
188  virtual void printTargetNameTo(Print& printer) const = 0;
189 
210  virtual void setZoneKey(uintptr_t zoneKey) = 0;
211 
219  virtual bool equalsZoneKey(uintptr_t zoneKey) const = 0;
220 
221  protected:
222  friend bool operator==(const ZoneProcessor& a, const ZoneProcessor& b);
223 
224  // Disable copy constructor and assignment operator.
225  ZoneProcessor(const ZoneProcessor&) = delete;
226  ZoneProcessor& operator=(const ZoneProcessor&) = delete;
227 
229  ZoneProcessor(uint8_t type):
230  mType(type) {}
231 
233  bool isFilled(int16_t year) const {
234  return mIsFilled && (year == mYear);
235  }
236 
238  virtual bool equals(const ZoneProcessor& other) const = 0;
239 
240  protected:
241  // The order of the fields is optimized to save space on 32-bit processors.
242  uint8_t const mType;
243  mutable bool mIsFilled = false;
244  mutable int16_t mYear = LocalDate::kInvalidYear;
245 };
246 
247 inline bool operator==(const ZoneProcessor& a, const ZoneProcessor& b) {
248  if (a.mType != b.mType) return false;
249  return a.equals(b);
250 }
251 
252 inline bool operator!=(const ZoneProcessor& a, const ZoneProcessor& b) {
253  return ! (a == b);
254 }
255 
256 namespace internal {
257 
259 struct MonthDay {
260  uint8_t month;
261  uint8_t day;
262 };
263 
281 MonthDay calcStartDayOfMonth(int16_t year, uint8_t month,
282  uint8_t onDayOfWeek, int8_t onDayOfMonth);
283 
284 } // internal
285 } // ace_time
286 
287 #endif
Result of a search for transition at a specific epochSeconds or a specific LocalDateTime.
Definition: ZoneProcessor.h:25
uint8_t fold
For findByLocalDateTime(), when type==kTypeOverlap, this is a copy of the requested LocalDateTime::fo...
Definition: ZoneProcessor.h:78
int16_t dstOffsetMinutes
DST offset of the resulting OffsetDateTime.
Definition: ZoneProcessor.h:84
int16_t reqStdOffsetMinutes
STD offset of the Transition which matched the epochSeconds requested by findByEpochSeconds(),...
Definition: ZoneProcessor.h:97
int16_t stdOffsetMinutes
STD offset of the resulting OffsetDateTime.
Definition: ZoneProcessor.h:81
int16_t reqDstOffsetMinutes
DST offset of the Transition which matched the epochSeconds requested by findByEpochSeconds(),...
const char * abbrev
Pointer to the abbreviation stored in the transient Transition::abbrev variable.
uint8_t type
Result of the findByEpochSeconds() or findByLocalDateTime() search methods.
Definition: ZoneProcessor.h:67
Class that holds the date-time as the components (year, month, day, hour, minute, second) without reg...
Definition: LocalDateTime.h:31
static const int16_t kInvalidYear
Sentinel year which indicates one or more of the following conditions:
Definition: LocalDate.h:61
Base interface for ZoneProcessor classes.
uint8_t getType() const
Return the kTypeXxx of the current instance.
ZoneProcessor(uint8_t type)
Constructor.
virtual FindResult findByEpochSeconds(acetime_t epochSeconds) const =0
Return the search results at given epochSeconds.
virtual void printTargetNameTo(Print &printer) const =0
Print the full identifier (e.g.
virtual void printNameTo(Print &printer) const =0
Print a human-readable identifier (e.g.
bool isFilled(int16_t year) const
Check if the Transition cache is filled for the given year.
virtual void printShortNameTo(Print &printer) const =0
Print a short human-readable identifier (e.g.
virtual uint32_t getZoneId() const =0
Return the unique stable zoneId.
virtual FindResult findByLocalDateTime(const LocalDateTime &ldt) const =0
Return the search results at given LocalDateTime.
virtual bool equalsZoneKey(uintptr_t zoneKey) const =0
Return true if ZoneProcessor is associated with the given opaque zoneKey.
virtual bool equals(const ZoneProcessor &other) const =0
Return true if equal.
virtual bool isLink() const =0
Return true if timezone is a Link entry pointing to a Zone entry.
void resetTransitionCache()
Reset the internal transition cache.
virtual void setZoneKey(uintptr_t zoneKey)=0
Set the opaque zoneKey of this object to a new value, reseting any internally cached information.
Identifiers used by implementation code which need to be publically exported.
int32_t acetime_t
Type for the number of seconds from epoch.
Definition: common.h:24
Internal identifiers used by implementation code, not intended to be publically exported.
The result of calcStartDayOfMonth().