AceTime  1.7.2
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock that can synchronize from an NTP server or an RTC chip.
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 uint32_t getZoneId() const = 0;
48 
53  virtual TimeOffset getUtcOffset(acetime_t epochSeconds) const = 0;
54 
60  virtual TimeOffset getDeltaOffset(acetime_t epochSeconds) const = 0;
61 
72  virtual const char* getAbbrev(acetime_t epochSeconds) const = 0;
73 
82  const = 0;
83 
85  virtual void printNameTo(Print& printer) const = 0;
86 
88  virtual void printShortNameTo(Print& printer) const = 0;
89 
105  virtual void setZoneKey(uintptr_t zoneKey) = 0;
106 
111  virtual bool equalsZoneKey(uintptr_t zoneKey) const = 0;
112 
113  protected:
114  friend bool operator==(const ZoneProcessor& a, const ZoneProcessor& b);
115 
116  // Disable copy constructor and assignment operator.
117  ZoneProcessor(const ZoneProcessor&) = delete;
118  ZoneProcessor& operator=(const ZoneProcessor&) = delete;
119 
121  ZoneProcessor(uint8_t type):
122  mType(type) {}
123 
125  virtual bool equals(const ZoneProcessor& other) const = 0;
126 
127  uint8_t const mType;
128 };
129 
130 inline bool operator==(const ZoneProcessor& a, const ZoneProcessor& b) {
131  if (a.mType != b.mType) return false;
132  return a.equals(b);
133 }
134 
135 inline bool operator!=(const ZoneProcessor& a, const ZoneProcessor& b) {
136  return ! (a == b);
137 }
138 
139 namespace internal {
140 
148 static const uint8_t kAbbrevSize = 6 + 1;
149 
151 struct MonthDay {
152  uint8_t month;
153  uint8_t day;
154 };
155 
173 MonthDay calcStartDayOfMonth(int16_t year, uint8_t month,
174  uint8_t onDayOfWeek, int8_t onDayOfMonth);
175 
176 } // internal
177 } // ace_time
178 
179 #endif
ace_time::ZoneProcessor::equals
virtual bool equals(const ZoneProcessor &other) const =0
Return true if equal.
ace_time::ZoneProcessor::printShortNameTo
virtual void printShortNameTo(Print &printer) const =0
Print a short human-readable identifier (e.g.
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::ZoneProcessor::getZoneId
virtual uint32_t getZoneId() const =0
Return the unique stable zoneId.
ace_time::ZoneProcessor::ZoneProcessor
ZoneProcessor(uint8_t type)
Constructor.
Definition: ZoneProcessor.h:121
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::printNameTo
virtual void printNameTo(Print &printer) const =0
Print a human-readable identifier (e.g.
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:151
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.