AceTime  2.2.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" // kAbbrevSize
10 #include "TimeOffset.h"
11 #include "OffsetDateTime.h"
12 
13 class Print;
14 
15 namespace ace_time {
16 
17 class LocalDateTime;
18 
24 class FindResult {
25  public:
26  static const uint8_t kTypeNotFound = 0;
27  static const uint8_t kTypeExact = 1;
28  static const uint8_t kTypeGap = 2;
29  static const uint8_t kTypeOverlap = 3;
30 
66  uint8_t type = kTypeNotFound;
67 
77  uint8_t fold = 0;
78 
80  int16_t stdOffsetMinutes = 0;
81 
83  int16_t dstOffsetMinutes = 0;
84 
96  int16_t reqStdOffsetMinutes = 0;
97 
109  int16_t reqDstOffsetMinutes = 0;
110 
116  const char* abbrev = "";
117 };
118 
142  public:
144  uint8_t getType() const { return mType; }
145 
150  void resetTransitionCache() { mIsFilled = false; }
151 
153  virtual bool isLink() const = 0;
154 
156  virtual uint32_t getZoneId() const = 0;
157 
160  const LocalDateTime& ldt) const = 0;
161 
164  acetime_t epochSeconds) const = 0;
165 
171  virtual void printNameTo(Print& printer) const = 0;
172 
179  virtual void printShortNameTo(Print& printer) const = 0;
180 
187  virtual void printTargetNameTo(Print& printer) const = 0;
188 
209  virtual void setZoneKey(uintptr_t zoneKey) = 0;
210 
218  virtual bool equalsZoneKey(uintptr_t zoneKey) const = 0;
219 
220  protected:
221  friend bool operator==(const ZoneProcessor& a, const ZoneProcessor& b);
222 
223  // Disable copy constructor and assignment operator.
224  ZoneProcessor(const ZoneProcessor&) = delete;
225  ZoneProcessor& operator=(const ZoneProcessor&) = delete;
226 
228  ZoneProcessor(uint8_t type):
229  mType(type) {}
230 
232  bool isFilled(int16_t year) const {
233  return mIsFilled && (year == mYear);
234  }
235 
237  virtual bool equals(const ZoneProcessor& other) const = 0;
238 
239  protected:
240  // The order of the fields is optimized to save space on 32-bit processors.
241  uint8_t const mType;
242  mutable bool mIsFilled = false;
243  mutable int16_t mYear = LocalDate::kInvalidYear;
244 };
245 
246 inline bool operator==(const ZoneProcessor& a, const ZoneProcessor& b) {
247  if (a.mType != b.mType) return false;
248  return a.equals(b);
249 }
250 
251 inline bool operator!=(const ZoneProcessor& a, const ZoneProcessor& b) {
252  return ! (a == b);
253 }
254 
255 namespace internal {
256 
258 struct MonthDay {
259  uint8_t month;
260  uint8_t day;
261 };
262 
280 MonthDay calcStartDayOfMonth(int16_t year, uint8_t month,
281  uint8_t onDayOfWeek, int8_t onDayOfMonth);
282 
283 } // internal
284 } // ace_time
285 
286 #endif
Result of a search for transition at a specific epochSeconds or a specific LocalDateTime.
Definition: ZoneProcessor.h:24
uint8_t fold
For findByLocalDateTime(), when type==kTypeOverlap, this is a copy of the requested LocalDateTime::fo...
Definition: ZoneProcessor.h:77
int16_t dstOffsetMinutes
DST offset of the resulting OffsetDateTime.
Definition: ZoneProcessor.h:83
int16_t reqStdOffsetMinutes
STD offset of the Transition which matched the epochSeconds requested by findByEpochSeconds(),...
Definition: ZoneProcessor.h:96
int16_t stdOffsetMinutes
STD offset of the resulting OffsetDateTime.
Definition: ZoneProcessor.h:80
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:66
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
The result of calcStartDayOfMonth().