AceTime  1.7.3
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 kTypeError:
14  case kTypeReserved:
15  printer.print("<Error>");
16  break;
17 
18  case kTypeManual:
19  if (isUtc()) {
20  printer.print("UTC");
21  } else {
22  TimeOffset::forMinutes(mStdOffsetMinutes).printTo(printer);
23  TimeOffset::forMinutes(mDstOffsetMinutes).printTo(printer);
24  }
25  break;
26 
27  default:
28  getBoundZoneProcessor()->printNameTo(printer);
29  break;
30  }
31 }
32 
33 void TimeZone::printShortTo(Print& printer) const {
34  switch (mType) {
35  case kTypeError:
36  case kTypeReserved:
37  printer.print("<Error>");
38  break;
39 
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) ? "D" : "S");
49  printer.print(')');
50  }
51  break;
52 
53  default:
54  getBoundZoneProcessor()->printShortNameTo(printer);
55  break;
56  }
57 }
58 
59 }
ace_time::TimeZone::printTo
void printTo(Print &printer) const
Print the text representation of the time zone using the full canonical time zone name or UTC offset ...
Definition: TimeZone.cpp:11
ace_time::ZoneProcessor::printShortNameTo
virtual void printShortNameTo(Print &printer) const =0
Print a short human-readable identifier (e.g.
ace_time::TimeZone::isUtc
bool isUtc() const
Return true if UTC (+00:00+00:00).
Definition: TimeZone.h:364
ace_time::TimeZone::kTypeManual
static const uint8_t kTypeManual
Manual STD offset and DST offset.
Definition: TimeZone.h:91
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:33
ace_time::ZoneProcessor::printNameTo
virtual void printNameTo(Print &printer) const =0
Print a human-readable identifier (e.g.
ace_time::TimeZone::kTypeReserved
static const uint8_t kTypeReserved
Reserved for future use.
Definition: TimeZone.h:94
ace_time::TimeZone::kTypeError
static const uint8_t kTypeError
A TimeZone that represents an invalid condition.
Definition: TimeZone.h:88
ace_time::TimeOffset::forMinutes
static TimeOffset forMinutes(int16_t minutes)
Create TimeOffset from minutes from 00:00.
Definition: TimeOffset.h:83