From e9a8e44a7a2e73725862467033ec3c837d86aa57 Mon Sep 17 00:00:00 2001 From: Yuri Trikoz Date: Thu, 25 Jun 2020 20:13:20 +0300 Subject: [PATCH] time --- include/Clock.h | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/include/Clock.h b/include/Clock.h index 94377691..00ece8f8 100644 --- a/include/Clock.h +++ b/include/Clock.h @@ -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() {