AceTime  3.0.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 "OffsetDateTime.h"
11 
12 class Print;
13 
14 namespace ace_time {
15 
16 class LocalDateTime;
17 
23 class FindResult {
24  public:
25  static const uint8_t kTypeNotFound = 0;
26  static const uint8_t kTypeExact = 1;
27  static const uint8_t kTypeGap = 2;
28  static const uint8_t kTypeOverlap = 3;
29 
65  uint8_t type = kTypeNotFound;
66 
76  uint8_t fold = 0;
77 
79  int32_t stdOffsetSeconds = 0;
80 
82  int32_t dstOffsetSeconds = 0;
83 
95  int32_t reqStdOffsetSeconds = 0;
96 
108  int32_t reqDstOffsetSeconds = 0;
109 
115  const char* abbrev = "";
116 };
117 
141  public:
143  uint8_t getType() const { return mType; }
144 
146  virtual bool isLink() const = 0;
147 
149  virtual uint32_t getZoneId() const = 0;
150 
153  const LocalDateTime& ldt) const = 0;
154 
157  acetime_t epochSeconds) const = 0;
158 
164  virtual void printNameTo(Print& printer) const = 0;
165 
172  virtual void printShortNameTo(Print& printer) const = 0;
173 
180  virtual void printTargetNameTo(Print& printer) const = 0;
181 
202  virtual void setZoneKey(uintptr_t zoneKey) = 0;
203 
211  virtual bool equalsZoneKey(uintptr_t zoneKey) const = 0;
212 
213  protected:
214  friend bool operator==(const ZoneProcessor& a, const ZoneProcessor& b);
215 
216  // Disable copy constructor and assignment operator.
217  ZoneProcessor(const ZoneProcessor&) = delete;
218  ZoneProcessor& operator=(const ZoneProcessor&) = delete;
219 
221  ZoneProcessor(uint8_t type):
222  mType(type) {}
223 
229  bool isFilled(int16_t year) const {
230  return year == mYear && mEpochYear == Epoch::currentEpochYear();
231  }
232 
234  virtual bool equals(const ZoneProcessor& other) const = 0;
235 
236  protected:
237  // The order of the fields is optimized to save space on 32-bit processors.
243  uint8_t const mType;
244 
249  mutable int16_t mYear = LocalDate::kInvalidYear;
250 
256 };
257 
258 inline bool operator==(const ZoneProcessor& a, const ZoneProcessor& b) {
259  if (a.mType != b.mType) return false;
260  return a.equals(b);
261 }
262 
263 inline bool operator!=(const ZoneProcessor& a, const ZoneProcessor& b) {
264  return ! (a == b);
265 }
266 
268 struct MonthDay {
269  uint8_t month;
270  uint8_t day;
271 };
272 
290 MonthDay calcStartDayOfMonth(int16_t year, uint8_t month,
291  uint8_t onDayOfWeek, int8_t onDayOfMonth);
292 
349 void createAbbreviation(
350  char* dest,
351  uint8_t destSize,
352  const char* format,
353  int32_t stdSeconds,
354  int32_t dstSeconds,
355  const char* letterString);
356 
357 } // ace_time
358 
359 #endif
static int16_t currentEpochYear()
Get the current epoch year.
Definition: Epoch.h:27
Result of a search for transition at a specific epochSeconds or a specific LocalDateTime.
Definition: ZoneProcessor.h:23
uint8_t fold
For findByLocalDateTime(), when type==kTypeOverlap, this is a copy of the requested LocalDateTime::fo...
Definition: ZoneProcessor.h:76
int32_t stdOffsetSeconds
STD offset of the resulting OffsetDateTime.
Definition: ZoneProcessor.h:79
int32_t dstOffsetSeconds
DST offset of the resulting OffsetDateTime.
Definition: ZoneProcessor.h:82
int32_t reqDstOffsetSeconds
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.
int32_t reqStdOffsetSeconds
STD offset of the Transition which matched the epochSeconds requested by findByEpochSeconds(),...
Definition: ZoneProcessor.h:95
uint8_t type
Result of the findByEpochSeconds() or findByLocalDateTime() search methods.
Definition: ZoneProcessor.h:65
Class that holds the date-time as the components (year, month, day, hour, minute, second) without reg...
Definition: LocalDateTime.h:30
static const int16_t kInvalidYear
Sentinel year which indicates one or more of the following conditions:
Definition: LocalDate.h:58
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.
int16_t mYear
Year that was used to calculate the transitions in the current cache.
bool isFilled(int16_t year) const
Check if the Transition cache is filled for the given year and current epochYear.
virtual void printShortNameTo(Print &printer) const =0
Print a short human-readable identifier (e.g.
uint8_t const mType
User-visible indicator of the subclass of ZoneProcessor, which implments a specific time-zone algorit...
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.
int16_t mEpochYear
Epoch year that was used to calculate the transitions in the current cache.
virtual bool isLink() const =0
Return true if timezone is a Link entry pointing to a Zone entry.
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().