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
140 class ZoneProcessor {
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
152 virtual FindResult findByLocalDateTime(
153 const LocalDateTime& ldt) const = 0;
154
156 virtual FindResult findByEpochSeconds(
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
255 mutable int16_t mEpochYear = LocalDate::kInvalidYear;
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
ace_time::Epoch::currentEpochYear
static int16_t currentEpochYear()
Get the current epoch year.
Definition: Epoch.h:27
ace_time::FindResult
Result of a search for transition at a specific epochSeconds or a specific LocalDateTime.
Definition: ZoneProcessor.h:23
ace_time::FindResult::fold
uint8_t fold
For findByLocalDateTime(), when type==kTypeOverlap, this is a copy of the requested LocalDateTime::fo...
Definition: ZoneProcessor.h:76
ace_time::FindResult::stdOffsetSeconds
int32_t stdOffsetSeconds
STD offset of the resulting OffsetDateTime.
Definition: ZoneProcessor.h:79
ace_time::FindResult::dstOffsetSeconds
int32_t dstOffsetSeconds
DST offset of the resulting OffsetDateTime.
Definition: ZoneProcessor.h:82
ace_time::FindResult::reqDstOffsetSeconds
int32_t reqDstOffsetSeconds
DST offset of the Transition which matched the epochSeconds requested by findByEpochSeconds(),...
Definition: ZoneProcessor.h:108
ace_time::FindResult::abbrev
const char * abbrev
Pointer to the abbreviation stored in the transient Transition::abbrev variable.
Definition: ZoneProcessor.h:115
ace_time::FindResult::reqStdOffsetSeconds
int32_t reqStdOffsetSeconds
STD offset of the Transition which matched the epochSeconds requested by findByEpochSeconds(),...
Definition: ZoneProcessor.h:95
ace_time::FindResult::type
uint8_t type
Result of the findByEpochSeconds() or findByLocalDateTime() search methods.
Definition: ZoneProcessor.h:65
ace_time::LocalDateTime
Class that holds the date-time as the components (year, month, day, hour, minute, second) without reg...
Definition: LocalDateTime.h:30
ace_time::LocalDate::kInvalidYear
static const int16_t kInvalidYear
Sentinel year which indicates one or more of the following conditions:
Definition: LocalDate.h:58
ace_time::ZoneProcessor
Base interface for ZoneProcessor classes.
Definition: ZoneProcessor.h:140
ace_time::ZoneProcessor::getType
uint8_t getType() const
Return the kTypeXxx of the current instance.
Definition: ZoneProcessor.h:143
ace_time::ZoneProcessor::ZoneProcessor
ZoneProcessor(uint8_t type)
Constructor.
Definition: ZoneProcessor.h:221
ace_time::ZoneProcessor::findByEpochSeconds
virtual FindResult findByEpochSeconds(acetime_t epochSeconds) const =0
Return the search results at given epochSeconds.
ace_time::ZoneProcessor::printTargetNameTo
virtual void printTargetNameTo(Print &printer) const =0
Print the full identifier (e.g.
ace_time::ZoneProcessor::printNameTo
virtual void printNameTo(Print &printer) const =0
Print a human-readable identifier (e.g.
ace_time::ZoneProcessor::mYear
int16_t mYear
Year that was used to calculate the transitions in the current cache.
Definition: ZoneProcessor.h:249
ace_time::ZoneProcessor::isFilled
bool isFilled(int16_t year) const
Check if the Transition cache is filled for the given year and current epochYear.
Definition: ZoneProcessor.h:229
ace_time::ZoneProcessor::printShortNameTo
virtual void printShortNameTo(Print &printer) const =0
Print a short human-readable identifier (e.g.
ace_time::ZoneProcessor::mType
uint8_t const mType
User-visible indicator of the subclass of ZoneProcessor, which implments a specific time-zone algorit...
Definition: ZoneProcessor.h:243
ace_time::ZoneProcessor::getZoneId
virtual uint32_t getZoneId() const =0
Return the unique stable zoneId.
ace_time::ZoneProcessor::findByLocalDateTime
virtual FindResult findByLocalDateTime(const LocalDateTime &ldt) const =0
Return the search results at given LocalDateTime.
ace_time::ZoneProcessor::equalsZoneKey
virtual bool equalsZoneKey(uintptr_t zoneKey) const =0
Return true if ZoneProcessor is associated with the given opaque zoneKey.
ace_time::ZoneProcessor::equals
virtual bool equals(const ZoneProcessor &other) const =0
Return true if equal.
ace_time::ZoneProcessor::mEpochYear
int16_t mEpochYear
Epoch year that was used to calculate the transitions in the current cache.
Definition: ZoneProcessor.h:255
ace_time::ZoneProcessor::isLink
virtual bool isLink() const =0
Return true if timezone is a Link entry pointing to a Zone entry.
ace_time::ZoneProcessor::setZoneKey
virtual void setZoneKey(uintptr_t zoneKey)=0
Set the opaque zoneKey of this object to a new value, reseting any internally cached information.
common.h
Identifiers used by implementation code which need to be publically exported.
ace_time::acetime_t
int32_t acetime_t
Type for the number of seconds from epoch.
Definition: common.h:24
ace_time::MonthDay
The result of calcStartDayOfMonth().
Definition: ZoneProcessor.h:268