AceTime  2.2.0
Date and time classes for Arduino that support timezones from the TZ Database.
BasicZone.h
1 /*
2  * MIT License
3  * Copyright (c) 2019 Brian T. Park
4  */
5 
6 #ifndef ACE_TIME_BASIC_ZONE_H
7 #define ACE_TIME_BASIC_ZONE_H
8 
9 #include <AceCommon.h> // KString
10 #include "../zoneinfo/ZoneInfo.h"
11 #include "../zoneinfo/Brokers.h"
12 
13 class Print;
14 
15 namespace ace_time {
16 
22 class BasicZone {
23  public:
28  BasicZone(const basic::ZoneInfo* zoneInfo):
29  mZoneInfoBroker(zoneInfo) {}
30 
36  BasicZone(const basic::ZoneInfoBroker& zoneInfo):
37  mZoneInfoBroker(zoneInfo) {}
38 
39  // Use default copy constructor and assignment operator
40  BasicZone(const BasicZone&) = default;
41  BasicZone& operator=(const BasicZone&) = default;
42 
44  bool isNull() const { return mZoneInfoBroker.isNull(); }
45 
47  void printNameTo(Print& printer) const;
48 
54  void printShortNameTo(Print& printer) const;
55 
57  uint32_t zoneId() const {
58  return mZoneInfoBroker.zoneId();
59  }
60 
62  int16_t stdOffsetMinutes() const {
63  uint8_t numEras = mZoneInfoBroker.numEras();
64  basic::ZoneEraBroker zeb = mZoneInfoBroker.era(numEras - 1);
65  return zeb.offsetMinutes();
66  }
67 
69  ace_common::KString kname() const {
70  const auto* name = isNull() ? nullptr : mZoneInfoBroker.name();
71  const internal::ZoneContext* zoneContext = mZoneInfoBroker.zoneContext();
72  return ace_common::KString(
73  name, zoneContext->fragments, zoneContext->numFragments);
74  }
75 
76  private:
77  basic::ZoneInfoBroker mZoneInfoBroker;
78 };
79 
80 }
81 
82 #endif
A thin wrapper around a basic::ZoneInfo data structure to provide a stable API access to some useful ...
Definition: BasicZone.h:22
ace_common::KString kname() const
Return the name as a KString.
Definition: BasicZone.h:69
uint32_t zoneId() const
Return the zoneId of the current zoneInfo.
Definition: BasicZone.h:57
int16_t stdOffsetMinutes() const
Return the STDOFF of the last ZoneEra.
Definition: BasicZone.h:62
BasicZone(const basic::ZoneInfo *zoneInfo)
Constructor from a raw basic::ZoneInfo* pointer, intended for manual inspection of a ZoneInfo record.
Definition: BasicZone.h:28
bool isNull() const
Return true if zoneInfo is null.
Definition: BasicZone.h:44
BasicZone(const basic::ZoneInfoBroker &zoneInfo)
Constructor from a basic::ZoneInfoBroker, used by BasicZoneProcessor.
Definition: BasicZone.h:36
void printShortNameTo(Print &printer) const
Print the short pretty zone name to the printer.
Definition: BasicZone.cpp:27
void printNameTo(Print &printer) const
Print the full zone name to printer.
Definition: BasicZone.cpp:20
Data broker for accessing ZoneEra.
Definition: Brokers.h:212
Metadata about the zone database.
Definition: ZoneContext.h:16
uint8_t numFragments
Number of fragments.
Definition: ZoneContext.h:65
const char *const * fragments
Zone Name fragment list.
Definition: ZoneContext.h:68