AceTime  2.3.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 "../zoneinfo/infos.h"
11 #include "../zoneinfo/brokers.h"
12 #include "TimeOffset.h"
13 
14 class Print;
15 
16 namespace ace_time {
17 
24 class ExtendedZone {
25  public:
30  ExtendedZone(const extended::ZoneInfo* zoneInfo):
31  mZoneInfoBroker(zoneInfo) {}
32 
39  mZoneInfoBroker(zoneInfo) {}
40 
41  // Use default copy constructor and assignment operator
42  ExtendedZone(const ExtendedZone&) = default;
43  ExtendedZone& operator=(const ExtendedZone&) = 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  extended::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  extended::ZoneContextBroker zoneContext = mZoneInfoBroker.zoneContext();
74  return ace_common::KString(
75  name, zoneContext.fragments(), zoneContext.numFragments());
76  }
77 
78  private:
79  extended::ZoneInfoBroker mZoneInfoBroker;
80 };
81 
82 }
83 
84 #endif
A thin wrapper around an extended::ZoneInfo data structure to provide a stable API access to some use...
Definition: ExtendedZone.h:24
bool isNull() const
Return true if zoneInfo is null.
Definition: ExtendedZone.h:46
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:38
uint32_t zoneId() const
Return the zoneId of the current zoneInfo.
Definition: ExtendedZone.h:59
TimeOffset stdOffset() const
Return the STDOFF of the last ZoneEra.
Definition: ExtendedZone.h:64
ace_common::KString kname() const
Return the name as a KString.
Definition: ExtendedZone.h:71
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:30
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