AceTime 2.4.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
38 ExtendedZone(const extended::ZoneInfoBroker& zoneInfo):
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
64 TimeOffset stdOffset() const {
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
ace_time::ExtendedZone
A thin wrapper around an extended::ZoneInfo data structure to provide a stable API access to some use...
Definition: ExtendedZone.h:24
ace_time::ExtendedZone::isNull
bool isNull() const
Return true if zoneInfo is null.
Definition: ExtendedZone.h:46
ace_time::ExtendedZone::printNameTo
void printNameTo(Print &printer) const
Print the full zone name to printer.
Definition: ExtendedZone.cpp:18
ace_time::ExtendedZone::ExtendedZone
ExtendedZone(const extended::ZoneInfoBroker &zoneInfo)
Constructor from an extended::ZoneInfoBroker, used by ExtendedZoneProcessor.
Definition: ExtendedZone.h:38
ace_time::ExtendedZone::zoneId
uint32_t zoneId() const
Return the zoneId of the current zoneInfo.
Definition: ExtendedZone.h:59
ace_time::ExtendedZone::stdOffset
TimeOffset stdOffset() const
Return the STDOFF of the last ZoneEra.
Definition: ExtendedZone.h:64
ace_time::ExtendedZone::kname
ace_common::KString kname() const
Return the name as a KString.
Definition: ExtendedZone.h:71
ace_time::ExtendedZone::printShortNameTo
void printShortNameTo(Print &printer) const
Print the short pretty zone name to the printer.
Definition: ExtendedZone.cpp:25
ace_time::ExtendedZone::ExtendedZone
ExtendedZone(const extended::ZoneInfo *zoneInfo)
Constructor from a raw extended::ZoneInfo* pointer, intended for manual inspection of a ZoneInfo reco...
Definition: ExtendedZone.h:30
ace_time::TimeOffset
A thin wrapper that represents a time offset from a reference point, usually 00:00 at UTC,...
Definition: TimeOffset.h:56
ace_time::TimeOffset::forSeconds
static TimeOffset forSeconds(int32_t seconds)
Create TimeOffset from seconds from 00:00.
Definition: TimeOffset.h:96
ace_time::zoneinfolow::ZoneContextBroker
Data broker for accessing a ZoneContext.
Definition: BrokersLow.h:91
ace_time::zoneinfolow::ZoneEraBroker
Data broker for accessing ZoneEra.
Definition: BrokersLow.h:297
ace_time::zoneinfolow::ZoneInfoBroker< ZoneContext, ZoneInfo, ZoneEra, ZonePolicy, ZoneRule >
ace_time::zoneinfolow::ZoneInfo
Representation of a given time zone, implemented as an array of ZoneEra records.
Definition: ZoneInfoLow.h:320