AceTime  2.2.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 
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 void TimeZone::printTargetNameTo(Print& printer) const {
60  if (isLink()) {
61  getBoundZoneProcessor()->printTargetNameTo(printer);
62  }
63 }
64 
65 }
static TimeOffset forMinutes(int16_t minutes)
Create TimeOffset from minutes from 00:00.
Definition: TimeOffset.h:83
void printTo(Print &printer) const
Print the human readable string.
Definition: TimeOffset.cpp:15
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
void printTargetNameTo(Print &printer) const
Print the name of the target zone if the current time zone is a Link.
Definition: TimeZone.cpp:59
bool isUtc() const
Return true if UTC (+00:00+00:00).
Definition: TimeZone.h:460
bool isLink() const
Return true if timezone is a Link entry pointing to a Zone entry.
Definition: TimeZone.h:268
void printShortTo(Print &printer) const
Print the short human readable representation of the time zone.
Definition: TimeZone.cpp:33
static const uint8_t kTypeError
A TimeZone that represents an invalid condition.
Definition: TimeZone.h:88
static const uint8_t kTypeReserved
Reserved for future use.
Definition: TimeZone.h:94
static const uint8_t kTypeManual
Manual STD offset and DST offset.
Definition: TimeZone.h:91
virtual void printTargetNameTo(Print &printer) const =0
Print the full identifier (e.g.
virtual void printNameTo(Print &printer) const =0
Print a human-readable identifier (e.g.
virtual void printShortNameTo(Print &printer) const =0
Print a short human-readable identifier (e.g.