forked from ironcannibal/led-sectional
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorldTimeAPI.h
More file actions
59 lines (49 loc) · 1.54 KB
/
WorldTimeAPI.h
File metadata and controls
59 lines (49 loc) · 1.54 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
/**
* ESP8266 (NodeMCU) client library for World Time API
*
* Copyright (c) 2018 Chris Vincent
*
* For more information, licensing and instructions, see https://github.com/project802/led-sectional
*/
#pragma once
#ifndef WORLDTIMEAPI_H
#define WORLDTIMEAPI_H
#include "Arduino.h"
class WorldTimeAPI {
public:
enum TimeMethod
{
TIME_USING_IP,
TIME_USING_TIMEZONE
};
private:
const char * _serverBaseURL = "http://worldtimeapi.org/api";
const unsigned long _updateIntervalMs = (24*60*60*1000);
const unsigned long _retryIntervalMs = (60*1000);
bool _receivedTime = false;
long _utcOffsetS = 0;
unsigned long _timeSinceEpochS = 0;
unsigned long _lastUpdateMs = 0;
unsigned long _lastAttemptMs = 0;
unsigned long _yearStartedUtc = 0;
TimeMethod _timeMethod;
String _timezone;
public:
WorldTimeAPI( TimeMethod method = TIME_USING_IP, String timezone = "America/New_York" );
bool update();
unsigned long getUnixTime( bool utc = true );
unsigned getDayOfWeek();
unsigned getHour();
unsigned getMinute();
unsigned getSecond();
String getFormattedTime();
unsigned getDayOfYear();
/**
* @return True if the current time has been sync'd
*/
bool timeReceived()
{
return this->_receivedTime;
}
};
#endif