AceTime 2.4.0 Date and time classes for Arduino that support timezones from the TZ Database.

TimeZoneData.h
1 /*
2 * MIT License
3 * Copyright (c) 2019 Brian T. Park
4 */
5
6 #ifndef ACE_TIME_TIME_ZONE_DATA_H
7 #define ACE_TIME_TIME_ZONE_DATA_H
8
9 #include <stdint.h>
10 #include "ZoneProcessor.h"
11
12 namespace ace_time {
13
38 struct TimeZoneData {
39 static const uint8_t kTypeError = 0;
40 static const uint8_t kTypeManual = 1;
41 static const uint8_t kTypeZoneId = 2;
42
47 TimeZoneData(uint32_t zid)
48 : type(kTypeZoneId),
49 zoneId(zid)
50 {}
51
53 TimeZoneData(int16_t stdMinutes, int16_t dstMinutes)
54 : type(kTypeManual),
55 stdOffsetMinutes(stdMinutes),
56 dstOffsetMinutes(dstMinutes)
57 {}
58
60 TimeZoneData()
61 : type(kTypeError),
62 zoneId(0)
63 {}
64
65 uint8_t type;
66
67 union {
76 struct {
77 int16_t stdOffsetMinutes;
78 int16_t dstOffsetMinutes;
79 };
80
85 uint32_t zoneId;
86 };
87 };
88
89 inline bool operator==(const TimeZoneData& a, const TimeZoneData& b) {
90 if (a.type != b.type) return false;
91 switch (a.type) {
92 case TimeZoneData::kTypeManual:
93 return (a.stdOffsetMinutes == b.stdOffsetMinutes)
94 && (a.dstOffsetMinutes == b.dstOffsetMinutes);
95 case TimeZoneData::kTypeZoneId:
96 return (a.zoneId == b.zoneId);
97 case TimeZoneData::kTypeError:
98 return true;
99 default:
100 return false;
101 }
102 }
103
104 inline bool operator!=(const TimeZoneData& a, const TimeZoneData& b) {
105 return ! (a == b);
106 }
107
108 }
109
110 #endif
ace_time::TimeZoneData
Data structure that captures the internal state of a TimeZone object with enough information so that ...
Definition: TimeZoneData.h:38
ace_time::TimeZoneData::zoneId
uint32_t zoneId
Both TimeZone::kTypeBasic and TimeZone::kTypeExtended are mapped to a TimeZoneData::kTypeZoneId.
Definition: TimeZoneData.h:85
ace_time::TimeZoneData::TimeZoneData
TimeZoneData()
Default constructor gives kTypeError sentinel.
Definition: TimeZoneData.h:60
ace_time::TimeZoneData::TimeZoneData
TimeZoneData(uint32_t zid)
Constructor for kTypeZoneId needed because C+11 does not have member initialization,...
Definition: TimeZoneData.h:47
ace_time::TimeZoneData::TimeZoneData
TimeZoneData(int16_t stdMinutes, int16_t dstMinutes)
Constructor for kTypeManual.
Definition: TimeZoneData.h:53