Fixed difference calculation

This commit is contained in:
cschwinne 2021-05-27 23:29:11 +02:00
parent 55b26751ae
commit 7cbc9d21b5

View File

@ -437,12 +437,13 @@ void calculateSunriseAndSunset() {
//time from JSON and HTTP API
void setTimeFromAPI(uint32_t timein) {
if (timein == 0 || timein == UINT32_MAX) return;
time_t prev = toki.second();
uint32_t prev = toki.second();
//only apply if more accurate or there is a significant difference to the "more accurate" time source
if (toki.getTimeSource() > TOKI_TS_JSON && abs(timein - prev) < 60L) return;
uint32_t diff = (timein > prev) ? timein - prev : prev - timein;
if (toki.getTimeSource() > TOKI_TS_JSON && diff < 60U) return;
toki.setTime(timein, TOKI_NO_MS_ACCURACY, TOKI_TS_JSON);
if (abs(timein - prev) > 60L) {
if (diff >= 60U) {
updateLocalTime();
calculateSunriseAndSunset();
}