AceTime  1.9.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 
61  : type(kTypeError),
62  zoneId(0)
63  {}
64 
65  uint8_t type;
66 
67  union {
69  struct {
70  int16_t stdOffsetMinutes;
71  int16_t dstOffsetMinutes;
72  };
73 
78  uint32_t zoneId;
79  };
80 };
81 
82 inline bool operator==(const TimeZoneData& a, const TimeZoneData& b) {
83  if (a.type != b.type) return false;
84  switch (a.type) {
85  case TimeZoneData::kTypeManual:
86  return (a.stdOffsetMinutes == b.stdOffsetMinutes)
87  && (a.dstOffsetMinutes == b.dstOffsetMinutes);
88  case TimeZoneData::kTypeZoneId:
89  return (a.zoneId == b.zoneId);
90  case TimeZoneData::kTypeError:
91  return true;
92  default:
93  return false;
94  }
95 }
96 
97 inline bool operator!=(const TimeZoneData& a, const TimeZoneData& b) {
98  return ! (a == b);
99 }
100 
101 }
102 
103 #endif
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
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::TimeZoneData
TimeZoneData()
Default constructor gives kTypeError sentinel.
Definition: TimeZoneData.h:60
ace_time::TimeZoneData::zoneId
uint32_t zoneId
Both TimeZone::kTypeBasic and TimeZone::kTypeExtended are mapped to a TimeZoneData::kTypeZoneId.
Definition: TimeZoneData.h:78