AceTime  2.3.0
Date and time classes for Arduino that support timezones from the TZ Database.
CompleteZone.h
1 /*
2  * MIT License
3  * Copyright (c) 2023 Brian T. Park
4  */
5 
6 #ifndef ACE_TIME_COMPLETE_ZONE_H
7 #define ACE_TIME_COMPLETE_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 
24 class CompleteZone {
25  public:
30  CompleteZone(const complete::ZoneInfo* zoneInfo):
31  mZoneInfoBroker(zoneInfo) {}
32 
39  mZoneInfoBroker(zoneInfo) {}
40 
41  // Use default copy constructor and assignment operator
42  CompleteZone(const CompleteZone&) = default;
43  CompleteZone& operator=(const CompleteZone&) = default;
44 
46  bool isNull() const { return mZoneInfoBroker.isNull(); }
47 
49  void printNameTo(Print& printer) const;
50 
56  void printShortNameTo(Print& printer) const;
57 
59  uint32_t zoneId() const {
60  return mZoneInfoBroker.zoneId();
61  }
62 
65  uint8_t numEras = mZoneInfoBroker.numEras();
66  complete::ZoneEraBroker zeb = mZoneInfoBroker.era(numEras - 1);
67  return TimeOffset::forSeconds(zeb.offsetSeconds());
68  }
69 
71  ace_common::KString kname() const {
72  const auto* name = isNull() ? nullptr : mZoneInfoBroker.name();
73  complete::ZoneContextBroker zoneContext = mZoneInfoBroker.zoneContext();
74  return ace_common::KString(
75  name, zoneContext.fragments(), zoneContext.numFragments());
76  }
77 
78  private:
79  complete::ZoneInfoBroker mZoneInfoBroker;
80 };
81 
82 }
83 
84 #endif
A thin wrapper around an complete::ZoneInfo data structure to provide a stable API access to some use...
Definition: CompleteZone.h:24
bool isNull() const
Return true if zoneInfo is null.
Definition: CompleteZone.h:46
CompleteZone(const complete::ZoneInfoBroker &zoneInfo)
Constructor from an complete::ZoneInfoBroker, used by CompleteZoneProcessor.
Definition: CompleteZone.h:38
CompleteZone(const complete::ZoneInfo *zoneInfo)
Constructor from a raw complete::ZoneInfo* pointer, intended for manual inspection of a ZoneInfo reco...
Definition: CompleteZone.h:30
ace_common::KString kname() const
Return the name as a KString.
Definition: CompleteZone.h:71
void printShortNameTo(Print &printer) const
Print the short pretty zone name to the printer.
uint32_t zoneId() const
Return the zoneId of the current zoneInfo.
Definition: CompleteZone.h:59
TimeOffset stdOffset() const
Return the STDOFF of the last ZoneEra.
Definition: CompleteZone.h:64
void printNameTo(Print &printer) const
Print the full zone name to printer.
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: BrokersHigh.h:81
Data broker for accessing ZoneEra.
Definition: BrokersHigh.h:270
Data broker for accessing ZoneInfo.
Definition: BrokersHigh.h:348
Representation of a given time zone, implemented as an array of ZoneEra records.
Definition: ZoneInfoHigh.h:277