forked from bxparks/AceTime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloDateTime.ino
More file actions
112 lines (92 loc) · 3.69 KB
/
HelloDateTime.ino
File metadata and controls
112 lines (92 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* A program to demonstrate the use of AceTime classes. It should print the
* following on the SERIAL_PORT_MONITOR port:
*
* Epoch Seconds: 605527200
* Unix Seconds: 1552212000
* === Los_Angeles:
* Time: 2019-03-10T03:00:00-07:00[America/Los_Angeles]
* Day of Week: Sunday
* Total UTC Offset: -07:00
* Zone: America/Los_Angeles
* Abbreviation: PDT
* === London:
* Time: 2019-03-10T10:00:00+00:00[Europe/London]
* Zone: Europe/London
* Abbreviation: GMT
* === Compare ZonedDateTime
* pacificTime.compareTo(londonTime): 0
* pacificTime == londonTime: false
*
*/
#include <AceTime.h>
using namespace ace_time;
// ZoneProcessor instances should be created statically at initialization time.
static BasicZoneProcessor pacificProcessor;
static BasicZoneProcessor londonProcessor;
void setup() {
#if ! defined(UNIX_HOST_DUINO)
delay(1000);
#endif
SERIAL_PORT_MONITOR.begin(115200);
while (!SERIAL_PORT_MONITOR); // Wait until SERIAL_PORT_MONITOR is ready - Leonardo/Micro
auto pacificTz = TimeZone::forZoneInfo(&zonedb::kZoneAmerica_Los_Angeles,
&pacificProcessor);
auto londonTz = TimeZone::forZoneInfo(&zonedb::kZoneEurope_London,
&londonProcessor);
// Create from components. 2019-03-10T03:00:00 is just after DST change in
// Los Angeles (2am goes to 3am).
auto startTime = ZonedDateTime::forComponents(
2019, 3, 10, 3, 0, 0, pacificTz);
SERIAL_PORT_MONITOR.print(F("Epoch Seconds: "));
acetime_t epochSeconds = startTime.toEpochSeconds();
SERIAL_PORT_MONITOR.println(epochSeconds);
SERIAL_PORT_MONITOR.print(F("Unix Seconds: "));
acetime_t unixSeconds = startTime.toUnixSeconds();
SERIAL_PORT_MONITOR.println(unixSeconds);
SERIAL_PORT_MONITOR.println(F("=== Los Angeles"));
auto pacificTime = ZonedDateTime::forEpochSeconds(epochSeconds, pacificTz);
SERIAL_PORT_MONITOR.print(F("Time: "));
pacificTime.printTo(SERIAL_PORT_MONITOR);
SERIAL_PORT_MONITOR.println();
SERIAL_PORT_MONITOR.print(F("Day of Week: "));
SERIAL_PORT_MONITOR.println(
DateStrings().dayOfWeekLongString(pacificTime.dayOfWeek()));
// Print info about UTC offset
TimeOffset offset = pacificTime.timeOffset();
SERIAL_PORT_MONITOR.print(F("Total UTC Offset: "));
offset.printTo(SERIAL_PORT_MONITOR);
SERIAL_PORT_MONITOR.println();
// Print info about the current time zone
SERIAL_PORT_MONITOR.print(F("Zone: "));
pacificTz.printTo(SERIAL_PORT_MONITOR);
SERIAL_PORT_MONITOR.println();
// Print the current time zone abbreviation, e.g. "PST" or "PDT"
SERIAL_PORT_MONITOR.print(F("Abbreviation: "));
SERIAL_PORT_MONITOR.print(pacificTz.getAbbrev(epochSeconds));
SERIAL_PORT_MONITOR.println();
// Create from epoch seconds. London is still on standard time.
auto londonTime = ZonedDateTime::forEpochSeconds(epochSeconds, londonTz);
SERIAL_PORT_MONITOR.println(F("=== London"));
SERIAL_PORT_MONITOR.print(F("Time: "));
londonTime.printTo(SERIAL_PORT_MONITOR);
SERIAL_PORT_MONITOR.println();
// Print info about the current time zone
SERIAL_PORT_MONITOR.print(F("Zone: "));
londonTz.printTo(SERIAL_PORT_MONITOR);
SERIAL_PORT_MONITOR.println();
// Print the current time zone abbreviation, e.g. "PST" or "PDT"
SERIAL_PORT_MONITOR.print(F("Abbreviation: "));
SERIAL_PORT_MONITOR.print(londonTz.getAbbrev(epochSeconds));
SERIAL_PORT_MONITOR.println();
SERIAL_PORT_MONITOR.println(F("=== Compare ZonedDateTime"));
SERIAL_PORT_MONITOR.print(F("pacificTime.compareTo(londonTime): "));
SERIAL_PORT_MONITOR.println(pacificTime.compareTo(londonTime));
SERIAL_PORT_MONITOR.print(F("pacificTime == londonTime: "));
SERIAL_PORT_MONITOR.println((pacificTime == londonTime) ? "true" : "false");
#if defined(UNIX_HOST_DUINO)
exit(0);
#endif
}
void loop() {
}