AceTime  1.2
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 "TimeZone.h"
8 
9 namespace ace_time {
10 
11 void TimeZone::printTo(Print& printer) const {
12  switch (mType) {
13  case kTypeManual:
14  if (isUtc()) {
15  printer.print("UTC");
16  } else {
17  TimeOffset::forMinutes(mStdOffsetMinutes).printTo(printer);
18  TimeOffset::forMinutes(mDstOffsetMinutes).printTo(printer);
19  }
20  return;
21  case kTypeBasic:
22  case kTypeExtended:
23  mZoneProcessor->printTo(printer);
24  return;
25  case kTypeBasicManaged:
26  case kTypeExtendedManaged:
27  {
28  ZoneProcessor* processor =
30  if (! processor) break;
31  processor->printTo(printer);
32  return;
33  }
34  }
35  printer.print("<Error>");
36 }
37 
38 void TimeZone::printShortTo(Print& printer) const {
39  switch (mType) {
40  case kTypeManual:
41  if (isUtc()) {
42  printer.print("UTC");
43  } else {
44  auto utcOffset = TimeOffset::forMinutes(
45  mStdOffsetMinutes + mDstOffsetMinutes);
46  utcOffset.printTo(printer);
47  printer.print('(');
48  printer.print((mDstOffsetMinutes != 0) ? "DST" : "STD");
49  printer.print(')');
50  }
51  return;
52  case kTypeBasic:
53  case kTypeExtended:
54  mZoneProcessor->printShortTo(printer);
55  return;
56  case kTypeBasicManaged:
57  case kTypeExtendedManaged:
58  {
59  ZoneProcessor* processor =
61  if (! processor) break;
62  processor->printShortTo(printer);
63  return;
64  }
65  }
66  printer.print("<Error>");
67 }
68 
69 }
ace_time::ZoneProcessorCache::getZoneProcessor
virtual ZoneProcessor * getZoneProcessor(const void *zoneInfo)=0
Get ZoneProcessor from either a basic::ZoneInfo or an extended::ZoneInfo.
ace_time::TimeZone::printTo
void printTo(Print &printer) const
Print the human readable representation of the time zone.
Definition: TimeZone.cpp:11
ace_time::TimeZone::mZoneProcessor
ZoneProcessor * mZoneProcessor
Used by kTypeBasic, kTypeExtended.
Definition: TimeZone.h:460
ace_time::TimeZone::isUtc
bool isUtc() const
Return true if UTC (+00:00+00:00).
Definition: TimeZone.h:311
ace_time::TimeZone::mZoneInfo
const void * mZoneInfo
Used by kTypeBasic, kTypeExtended, kTypeBasicManaged, kTypeExtendedManaged.
Definition: TimeZone.h:456
ace_time::TimeOffset::printTo
void printTo(Print &printer) const
Print the human readable string.
Definition: TimeOffset.cpp:15
ace_time::TimeZone::printShortTo
void printShortTo(Print &printer) const
Print the short human readable representation of the time zone.
Definition: TimeZone.cpp:38
ace_time::ZoneProcessor
Base interface for ZoneProcessor classes.
Definition: ZoneProcessor.h:45
ace_time::TimeOffset::forMinutes
static TimeOffset forMinutes(int16_t minutes)
Create TimeOffset from minutes from 00:00.
Definition: TimeOffset.h:83
ace_time::ZoneProcessor::printShortTo
virtual void printShortTo(Print &printer) const =0
Print a short human-readable identifier (e.g.
ace_time::TimeZone::mZoneProcessorCache
ZoneProcessorCache * mZoneProcessorCache
Used by kTypeBasicManaged, kTypeExtendedManaged.
Definition: TimeZone.h:463
ace_time::ZoneProcessor::printTo
virtual void printTo(Print &printer) const =0
Print a human-readable identifier (e.g.