AceTime  2.3.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/infos.h"
11 #include "../zoneinfo/brokers.h"
12 #include "TimeOffset.h"
13 
14 class Print;
15 
16 namespace ace_time {
17 
23 class BasicZone {
24  public:
29  BasicZone(const basic::ZoneInfo* zoneInfo):
30  mZoneInfoBroker(zoneInfo) {}
31 
37  BasicZone(const basic::ZoneInfoBroker& zoneInfo):
38  mZoneInfoBroker(zoneInfo) {}
39 
40  // Use default copy constructor and assignment operator
41  BasicZone(const BasicZone&) = default;
42  BasicZone& operator=(const BasicZone&) = 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 
64  uint8_t numEras = mZoneInfoBroker.numEras();
65  basic::ZoneEraBroker zeb = mZoneInfoBroker.era(numEras - 1);
66  return TimeOffset::forSeconds(zeb.offsetSeconds());
67  }
68 
70  ace_common::KString kname() const {
71  const auto* name = isNull() ? nullptr : mZoneInfoBroker.name();
72  basic::ZoneContextBroker zoneContext = mZoneInfoBroker.zoneContext();
73  return ace_common::KString(
74  name, zoneContext.fragments(), zoneContext.numFragments());
75  }
76 
77  private:
78  basic::ZoneInfoBroker mZoneInfoBroker;
79 };
80 
81 }
82 
83 #endif
A thin wrapper around a basic::ZoneInfo data structure to provide a stable API access to some useful ...
Definition: BasicZone.h:23
ace_common::KString kname() const
Return the name as a KString.
Definition: BasicZone.h:70
uint32_t zoneId() const
Return the zoneId of the current zoneInfo.
Definition: BasicZone.h:58
TimeOffset stdOffset() const
Return the STDOFF of the last ZoneEra.
Definition: BasicZone.h:63
BasicZone(const basic::ZoneInfo *zoneInfo)
Constructor from a raw basic::ZoneInfo* pointer, intended for manual inspection of a ZoneInfo record.
Definition: BasicZone.h:29
bool isNull() const
Return true if zoneInfo is null.
Definition: BasicZone.h:45
BasicZone(const basic::ZoneInfoBroker &zoneInfo)
Constructor from a basic::ZoneInfoBroker, used by BasicZoneProcessor.
Definition: BasicZone.h:37
void printShortNameTo(Print &printer) const
Print the short pretty zone name to the printer.
Definition: BasicZone.cpp:25
void printNameTo(Print &printer) const
Print the full zone name to printer.
Definition: BasicZone.cpp:18
A thin wrapper that represents a time offset from a reference point, usually 00:00 at UTC,...
Definition: TimeOffset.h:56
static TimeOffset forSeconds(int32_t seconds)
Create TimeOffset from seconds from 00:00.
Definition: TimeOffset.h:96
Data broker for accessing a ZoneContext.
Definition: BrokersLow.h:91
Data broker for accessing ZoneEra.
Definition: BrokersLow.h:297
Representation of a given time zone, implemented as an array of ZoneEra records.
Definition: ZoneInfoLow.h:302