AceTime  0.7
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock that can synchronize from an NTP server or an RTC chip.
TimeZone.cpp
1 /*
2  * MIT License
3  * Copyright (c) 2018 Brian T. Park
4  */
5 
6 #include <Print.h>
7 #include "common/util.h"
8 #include "TimeZone.h"
9 
10 namespace ace_time {
11 
12 void TimeZone::printTo(Print& printer) const {
13  switch (mType) {
14  case kTypeManual:
15  if (isUtc()) {
16  printer.print("UTC");
17  } else {
18  TimeOffset::forMinutes(mStdOffsetMinutes).printTo(printer);
19  TimeOffset::forMinutes(mDstOffsetMinutes).printTo(printer);
20  }
21  return;
22  case kTypeBasic:
23  case kTypeExtended:
24  mZoneProcessor->printTo(printer);
25  return;
26  case kTypeBasicManaged:
27  case kTypeExtendedManaged:
28  {
29  ZoneProcessor* processor =
31  if (! processor) break;
32  processor->printTo(printer);
33  return;
34  }
35  }
36  printer.print("<Error>");
37 }
38 
39 void TimeZone::printShortTo(Print& printer) const {
40  switch (mType) {
41  case kTypeManual:
42  if (isUtc()) {
43  printer.print("UTC");
44  } else {
45  auto utcOffset = TimeOffset::forMinutes(
46  mStdOffsetMinutes + mDstOffsetMinutes);
47  utcOffset.printTo(printer);
48  printer.print('(');
49  printer.print((mDstOffsetMinutes != 0) ? "DST" : "STD");
50  printer.print(')');
51  }
52  return;
53  case kTypeBasic:
54  case kTypeExtended:
55  mZoneProcessor->printShortTo(printer);
56  return;
57  case kTypeBasicManaged:
58  case kTypeExtendedManaged:
59  {
60  ZoneProcessor* processor =
62  if (! processor) break;
63  processor->printShortTo(printer);
64  return;
65  }
66  }
67  printer.print("<Error>");
68 }
69 
70 void TimeZone::printAbbrevTo(Print& printer, acetime_t epochSeconds) const {
71  switch (mType) {
72  case kTypeManual:
73  if (isUtc()) {
74  printer.print("UTC");
75  } else {
76  printer.print((mDstOffsetMinutes != 0) ? "DST" : "STD");
77  }
78  return;
79  case kTypeBasic:
80  case kTypeExtended:
81  printer.print(mZoneProcessor->getAbbrev(epochSeconds));
82  return;
83  case kTypeBasicManaged:
84  case kTypeExtendedManaged:
85  {
86  ZoneProcessor* processor =
88  if (! processor) break;
89  printer.print(processor->getAbbrev(epochSeconds));
90  return;
91  }
92  }
93  printer.print("<Error>");
94 }
95 
96 }
Base interface for ZoneProcessor classes.
Definition: ZoneProcessor.h:45
bool isUtc() const
Return true if UTC (+00:00+00:00).
Definition: TimeZone.h:268
virtual ZoneProcessor * getZoneProcessor(const void *zoneInfo)=0
Get ZoneProcessor from either a basic::ZoneInfo or an extended::ZoneInfo.
void printShortTo(Print &printer) const
Print the short human readable representation of the time zone.
Definition: TimeZone.cpp:39
void printTo(Print &printer) const
Print the human readable string.
Definition: TimeOffset.cpp:15
virtual void printShortTo(Print &printer) const =0
Print a short human-readable identifier (e.g.
const void * mZoneInfo
Used by kTypeBasic, kTypeExtended, kTypeBasicManaged, kTypeExtendedManaged.
Definition: TimeZone.h:421
void printTo(Print &printer) const
Print the human readable representation of the time zone.
Definition: TimeZone.cpp:12
virtual const char * getAbbrev(acetime_t epochSeconds) const =0
Return the time zone abbreviation at epochSeconds.
virtual void printTo(Print &printer) const =0
Print a human-readable identifier (e.g.
static TimeOffset forMinutes(int16_t minutes)
Create TimeOffset from minutes from 00:00.
Definition: TimeOffset.h:91
void printAbbrevTo(Print &printer, acetime_t epochSeconds) const
Print the time zone abbreviation for the given epochSeconds.
Definition: TimeZone.cpp:70
ZoneProcessor * mZoneProcessor
Used by kTypeBasic, kTypeExtended.
Definition: TimeZone.h:425
ZoneProcessorCache * mZoneProcessorCache
Used by kTypeBasicManaged, kTypeExtendedManaged.
Definition: TimeZone.h:428