This commit is contained in:
Yuri Trikoz
2020-06-25 20:13:20 +03:00
parent 6277d2a9db
commit e9a8e44a7a

View File

@@ -3,7 +3,7 @@
#include "Utils/TimeUtils.h"
#include "Utils/PrintMessage.h"
#include "time.h"
#include "TZ.h"
class Clock {
const char* MODULE = "Clock";
@@ -19,9 +19,7 @@ class Clock {
return _hasSynced;
}
void
setNtpPool(String ntp) {
void setNtpPool(String ntp) {
_ntp = ntp;
}
@@ -29,15 +27,6 @@ class Clock {
_timezone = timezone;
}
time_t getSystemTime() {
timeval tv{0, 0};
timezone tz = getTimeZone(getBiasInMinutes());
time_t epoch = 0;
if (gettimeofday(&tv, &tz) != -1)
epoch = tv.tv_sec;
return epoch;
}
void startSync() {
if (!_configured) {
pm.info("sync to: " + _ntp + " time zone: " + String(_timezone));
@@ -73,10 +62,20 @@ class Clock {
// delay(1000);
// }
// #endif
private:
bool hasTimeSynced() {
unsigned long now = time(nullptr);
return now > millis();
int uptime = millis() / 1000;
return getSystemTime() > uptime;
}
time_t getSystemTime() {
timeval tv{0, 0};
timezone tz = getTimeZone(getBiasInMinutes());
time_t epoch = 0;
if (gettimeofday(&tv, &tz) != -1) {
epoch = tv.tv_sec;
}
return epoch + getBiasInSeconds();
}
int getBiasInSeconds() {