File tree 2 files changed +14
-5
lines changed
2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -150,8 +150,8 @@ int NTPClient::getSeconds() {
150
150
return (this ->getEpochTime () % 60 );
151
151
}
152
152
153
- String NTPClient::getFormattedTime () {
154
- unsigned long rawTime = this ->getEpochTime ();
153
+ String NTPClient::getFormattedTime (unsigned long secs ) {
154
+ unsigned long rawTime = secs ? secs : this ->getEpochTime ();
155
155
unsigned long hours = (rawTime % 86400L ) / 3600 ;
156
156
String hoursStr = hours < 10 ? " 0" + String (hours) : String (hours);
157
157
@@ -199,3 +199,7 @@ void NTPClient::sendNTPPacket() {
199
199
this ->_udp ->write (this ->_packetBuffer , NTP_PACKET_SIZE);
200
200
this ->_udp ->endPacket ();
201
201
}
202
+
203
+ void NTPClient::setEpochTime (unsigned long secs) {
204
+ this ->_currentEpoc = secs;
205
+ }
Original file line number Diff line number Diff line change @@ -76,9 +76,9 @@ class NTPClient {
76
76
void setUpdateInterval (unsigned long updateInterval);
77
77
78
78
/* *
79
- * @return time formatted like `hh:mm:ss`
80
- */
81
- String getFormattedTime ();
79
+ * @return secs argument (or 0 for current time) formatted like `hh:mm:ss`
80
+ */
81
+ String getFormattedTime (unsigned long secs = 0 );
82
82
83
83
/* *
84
84
* @return time in seconds since Jan. 1, 1970
@@ -89,4 +89,9 @@ class NTPClient {
89
89
* Stops the underlying UDP client
90
90
*/
91
91
void end ();
92
+
93
+ /* *
94
+ * Replace the NTP-fetched time with seconds since Jan. 1, 1970
95
+ */
96
+ void setEpochTime (unsigned long secs);
92
97
};
You can’t perform that action at this time.
0 commit comments