forked from bxparks/AceTime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloZoneManager.ino
More file actions
55 lines (46 loc) · 1.71 KB
/
HelloZoneManager.ino
File metadata and controls
55 lines (46 loc) · 1.71 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
/*
* A program to demonstrate using the ZoneManager with the entire
* zoneinfo database loaded, creating 3 timezones in 3 different ways
* (createForZoneInfo(), createForZoneName() and createForZoneId()),
* then displaying the time in those zones. Should print the following:
*
* 2019-03-10T03:00:00-07:00[America/Los_Angeles]
* 2019-03-10T10:00:00+00:00[Europe/London]
* 2019-03-10T21:00:00+11:00[Australia/Sydney]
*/
#include <Arduino.h>
#include <AceTime.h>
using namespace ace_time;
// Create a BasicZoneManager with the entire TZ Database.
static const int CACHE_SIZE = 3;
static BasicZoneManager<CACHE_SIZE> manager(
zonedb::kZoneRegistrySize, zonedb::kZoneRegistry);
void setup() {
#if ! defined(UNIX_HOST_DUINO)
delay(1000);
#endif
SERIAL_PORT_MONITOR.begin(115200);
while (!SERIAL_PORT_MONITOR); // Wait Serial is ready - Leonardo/Micro
// Create Los Angeles by ZoneInfo
auto pacificTz = manager.createForZoneInfo(&zonedb::kZoneAmerica_Los_Angeles);
auto pacificTime = ZonedDateTime::forComponents(
2019, 3, 10, 3, 0, 0, pacificTz);
pacificTime.printTo(SERIAL_PORT_MONITOR);
SERIAL_PORT_MONITOR.println();
// Create London by ZoneName
auto londonTz = manager.createForZoneName("Europe/London");
auto londonTime = pacificTime.convertToTimeZone(londonTz);
londonTime.printTo(SERIAL_PORT_MONITOR);
SERIAL_PORT_MONITOR.println();
// Create Sydney by ZoneId
uint32_t syndeyId = BasicZone(&zonedb::kZoneAustralia_Sydney).zoneId();
auto sydneyTz = manager.createForZoneId(syndeyId);
auto sydneyTime = pacificTime.convertToTimeZone(sydneyTz);
sydneyTime.printTo(SERIAL_PORT_MONITOR);
SERIAL_PORT_MONITOR.println();
#if defined(UNIX_HOST_DUINO)
exit(0);
#endif
}
void loop() {
}