AceTime  1.11.1
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 "TimeOffset.h"
11 #include "OffsetDateTime.h"
12 
13 class Print;
14 
15 namespace ace_time {
16 
17 class LocalDateTime;
18 
42  public:
44  uint8_t getType() const { return mType; }
45 
47  virtual bool isLink() const = 0;
48 
56  virtual uint32_t getZoneId(bool followLink = false) const = 0;
57 
62  virtual TimeOffset getUtcOffset(acetime_t epochSeconds) const = 0;
63 
69  virtual TimeOffset getDeltaOffset(acetime_t epochSeconds) const = 0;
70 
81  virtual const char* getAbbrev(acetime_t epochSeconds) const = 0;
82 
91  const = 0;
92 
102  virtual OffsetDateTime getOffsetDateTime(acetime_t epochSeconds) const = 0;
103 
112  virtual void printNameTo(Print& printer, bool followLink = false) const = 0;
113 
123  virtual void printShortNameTo(Print& printer, bool followLink = false)
124  const = 0;
125 
141  virtual void setZoneKey(uintptr_t zoneKey) = 0;
142 
147  virtual bool equalsZoneKey(uintptr_t zoneKey) const = 0;
148 
149  protected:
150  friend bool operator==(const ZoneProcessor& a, const ZoneProcessor& b);
151 
152  // Disable copy constructor and assignment operator.
153  ZoneProcessor(const ZoneProcessor&) = delete;
154  ZoneProcessor& operator=(const ZoneProcessor&) = delete;
155 
157  ZoneProcessor(uint8_t type):
158  mType(type) {}
159 
161  virtual bool equals(const ZoneProcessor& other) const = 0;
162 
163  uint8_t const mType;
164 };
165 
166 inline bool operator==(const ZoneProcessor& a, const ZoneProcessor& b) {
167  if (a.mType != b.mType) return false;
168  return a.equals(b);
169 }
170 
171 inline bool operator!=(const ZoneProcessor& a, const ZoneProcessor& b) {
172  return ! (a == b);
173 }
174 
175 namespace internal {
176 
184 static const uint8_t kAbbrevSize = 6 + 1;
185 
187 struct MonthDay {
188  uint8_t month;
189  uint8_t day;
190 };
191 
209 MonthDay calcStartDayOfMonth(int16_t year, uint8_t month,
210  uint8_t onDayOfWeek, int8_t onDayOfMonth);
211 
212 } // internal
213 } // ace_time
214 
215 #endif
ace_time::ZoneProcessor::equals
virtual bool equals(const ZoneProcessor &other) const =0
Return true if equal.
ace_time::LocalDateTime
Class that holds the date-time as the components (year, month, day, hour, minute, second) without reg...
Definition: LocalDateTime.h:31
ace_time::ZoneProcessor::ZoneProcessor
ZoneProcessor(uint8_t type)
Constructor.
Definition: ZoneProcessor.h:157
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.
ace_time::ZoneProcessor::getType
uint8_t getType() const
Return the kTypeXxx of the current instance.
Definition: ZoneProcessor.h:44
ace_time::TimeOffset
A thin wrapper that represents a time offset from a reference point, usually 00:00 at UTC,...
Definition: TimeOffset.h:56
ace_time::ZoneProcessor::getDeltaOffset
virtual TimeOffset getDeltaOffset(acetime_t epochSeconds) const =0
Return the DST delta offset at epochSeconds.
ace_time::ZoneProcessor::isLink
virtual bool isLink() const =0
Return true if timezone is a Link entry pointing to a Zone entry.
ace_time::OffsetDateTime
The date (year, month, day), time (hour, minute, second) and offset from UTC (timeOffset).
Definition: OffsetDateTime.h:33
ace_time::ZoneProcessor::getAbbrev
virtual const char * getAbbrev(acetime_t epochSeconds) const =0
Return the time zone abbreviation at epochSeconds.
ace_time::ZoneProcessor
Base interface for ZoneProcessor classes.
Definition: ZoneProcessor.h:41
ace_time::ZoneProcessor::getUtcOffset
virtual TimeOffset getUtcOffset(acetime_t epochSeconds) const =0
Return the total UTC offset at epochSeconds, including DST offset.
ace_time::internal::MonthDay
The result of calcStartDayOfMonth().
Definition: ZoneProcessor.h:187
ace_time::ZoneProcessor::getZoneId
virtual uint32_t getZoneId(bool followLink=false) const =0
Return the unique stable zoneId.
ace_time::ZoneProcessor::printNameTo
virtual void printNameTo(Print &printer, bool followLink=false) const =0
Print a human-readable identifier (e.g.
ace_time::ZoneProcessor::printShortNameTo
virtual void printShortNameTo(Print &printer, bool followLink=false) const =0
Print a short human-readable identifier (e.g.
ace_time::ZoneProcessor::getOffsetDateTime
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...
ace_time::ZoneProcessor::equalsZoneKey
virtual bool equalsZoneKey(uintptr_t zoneKey) const =0
Return true if ZoneProcessor is associated with the given opaque zoneKey.