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