mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
time
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user