@@ -25,7 +25,7 @@ See more at http://blog.squix.ch
25
25
26
26
#include " TimeClient.h"
27
27
28
- TimeClient::TimeClient (int utcOffset) {
28
+ TimeClient::TimeClient (float utcOffset) {
29
29
myUtcOffset = utcOffset;
30
30
}
31
31
@@ -60,8 +60,11 @@ void TimeClient::updateTime() {
60
60
int parsedHours = line.substring (23 , 25 ).toInt ();
61
61
int parsedMinutes = line.substring (26 , 28 ).toInt ();
62
62
int parsedSeconds = line.substring (29 , 31 ).toInt ();
63
+ Serial.println (String (parsedHours) + " :" + String (parsedMinutes) + " :" + String (parsedSeconds));
63
64
64
65
localEpoc = (parsedHours * 60 * 60 + parsedMinutes * 60 + parsedSeconds);
66
+ Serial.println (localEpoc);
67
+ localMillisAtUpdate = millis ();
65
68
}
66
69
}
67
70
}
@@ -72,7 +75,7 @@ String TimeClient::getHours() {
72
75
if (localEpoc == 0 ) {
73
76
return " --" ;
74
77
}
75
- int hours = (getCurrentEpoch ( ) % 86400L ) / 3600 + myUtcOffset ;
78
+ int hours = (( getCurrentEpochWithUtcOffset ( ) % 86400L ) / 3600 ) % 24 ;
76
79
if (hours < 10 ) {
77
80
return " 0" + String (hours);
78
81
}
@@ -83,7 +86,7 @@ String TimeClient::getMinutes() {
83
86
if (localEpoc == 0 ) {
84
87
return " --" ;
85
88
}
86
- int minutes = ((getCurrentEpoch () % 3600 ) / 60 );
89
+ int minutes = ((getCurrentEpochWithUtcOffset () % 3600 ) / 60 );
87
90
if (minutes < 10 ) {
88
91
// In the first 10 minutes of each hour, we'll want a leading '0'
89
92
return " 0" + String (minutes);
@@ -94,7 +97,7 @@ String TimeClient::getSeconds() {
94
97
if (localEpoc == 0 ) {
95
98
return " --" ;
96
99
}
97
- int seconds = getCurrentEpoch () % 60 ;
100
+ int seconds = getCurrentEpochWithUtcOffset () % 60 ;
98
101
if ( seconds < 10 ) {
99
102
// In the first 10 seconds of each minute, we'll want a leading '0'
100
103
return " 0" + String (seconds);
@@ -110,3 +113,8 @@ long TimeClient::getCurrentEpoch() {
110
113
return localEpoc + ((millis () - localMillisAtUpdate) / 1000 );
111
114
}
112
115
116
+ long TimeClient::getCurrentEpochWithUtcOffset () {
117
+ return round (getCurrentEpoch () + 3600 * myUtcOffset + 86400L ) % 86400L ;
118
+ }
119
+
120
+
0 commit comments