AceTime 2.4.0 Date and time classes for Arduino that support timezones from the TZ Database.

TimeZone.cpp
1 /*
2 * MIT License
3 * Copyright (c) 2018 Brian T. Park
4 */
5
6 #include <Print.h>
7 #include "TimeZone.h"
8 #include "TimeOffset.h"
9
10 namespace ace_time {
11
12 void TimeZone::printTo(Print& printer) const {
13 switch (mType) {
14 case kTypeError:
15 case kTypeReserved:
16 printer.print("<Error>");
17 break;
18
19 case kTypeManual:
20 if (isUtc()) {
21 printer.print("UTC");
22 } else {
23 TimeOffset::forMinutes(mStdOffsetMinutes).printTo(printer);
24 TimeOffset::forMinutes(mDstOffsetMinutes).printTo(printer);
25 }
26 break;
27
28 default:
29 getBoundZoneProcessor()->printNameTo(printer);
30 break;
31 }
32 }
33
34 void TimeZone::printShortTo(Print& printer) const {
35 switch (mType) {
36 case kTypeError:
37 case kTypeReserved:
38 printer.print("<Error>");
39 break;
40
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) ? "D" : "S");
50 printer.print(')');
51 }
52 break;
53
54 default:
55 getBoundZoneProcessor()->printShortNameTo(printer);
56 break;
57 }
58 }
59
60 void TimeZone::printTargetNameTo(Print& printer) const {
61 if (isLink()) {
62 getBoundZoneProcessor()->printTargetNameTo(printer);
63 }
64 }
65
66 }
ace_time::TimeOffset::forMinutes
static TimeOffset forMinutes(int16_t minutes)
Create TimeOffset from minutes from 00:00.
Definition: TimeOffset.h:91
ace_time::TimeOffset::printTo
void printTo(Print &printer) const
Print the human readable string, including a "-" or "+" prefix, in the form of "+/-hh:mm" or "+/-hh:m...
Definition: TimeOffset.cpp:15
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:12
ace_time::TimeZone::printTargetNameTo
void printTargetNameTo(Print &printer) const
Print the name of the target zone if the current time zone is a Link.
Definition: TimeZone.cpp:60
ace_time::TimeZone::isUtc
bool isUtc() const
Return true if UTC (+00:00+00:00).
Definition: TimeZone.h:463
ace_time::TimeZone::isLink
bool isLink() const
Return true if timezone is a Link entry pointing to a Zone entry.
Definition: TimeZone.h:271
ace_time::TimeZone::printShortTo
void printShortTo(Print &printer) const
Print the short human readable representation of the time zone.
Definition: TimeZone.cpp:34
ace_time::TimeZone::kTypeError
static const uint8_t kTypeError
A TimeZone that represents an invalid condition.
Definition: TimeZone.h:89
ace_time::TimeZone::kTypeReserved
static const uint8_t kTypeReserved
Reserved for future use.
Definition: TimeZone.h:95
ace_time::TimeZone::kTypeManual
static const uint8_t kTypeManual
Manual STD offset and DST offset.
Definition: TimeZone.h:92
ace_time::ZoneProcessor::printTargetNameTo
virtual void printTargetNameTo(Print &printer) const =0
Print the full identifier (e.g.
ace_time::ZoneProcessor::printNameTo
virtual void printNameTo(Print &printer) const =0
Print a human-readable identifier (e.g.
ace_time::ZoneProcessor::printShortNameTo
virtual void printShortNameTo(Print &printer) const =0
Print a short human-readable identifier (e.g.