From 225cab676a0f56ccb81232b6e8378991b2eacf61 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Sun, 27 Oct 2024 14:03:44 +0100 Subject: [PATCH] Fix: Take DST into account when recalculating the sunrise sunset time If it is not considered the correct sunset / sunrise time is only calculated at the next day Fixes: #2377 --- src/SunPosition.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/SunPosition.cpp b/src/SunPosition.cpp index f1e1bee4a..5a2f27a2a 100644 --- a/src/SunPosition.cpp +++ b/src/SunPosition.cpp @@ -7,6 +7,8 @@ #include "Utils.h" #include +#define CALC_UNIQUE_ID (((timeinfo.tm_year << 9) | (timeinfo.tm_mon << 5) | timeinfo.tm_mday) << 1 | timeinfo.tm_isdst) + SunPositionClass SunPosition; SunPositionClass::SunPositionClass() @@ -57,7 +59,7 @@ bool SunPositionClass::checkRecalcDayChanged() const time(&now); localtime_r(&now, &timeinfo); // don't use getLocalTime() as there could be a delay of 10ms - const uint32_t ymd = (timeinfo.tm_year << 9) | (timeinfo.tm_mon << 5) | timeinfo.tm_mday; + const uint32_t ymd = CALC_UNIQUE_ID; return _lastSunPositionCalculatedYMD != ymd; } @@ -67,7 +69,7 @@ void SunPositionClass::updateSunData() struct tm timeinfo; const bool gotLocalTime = getLocalTime(&timeinfo, 5); - _lastSunPositionCalculatedYMD = (timeinfo.tm_year << 9) | (timeinfo.tm_mon << 5) | timeinfo.tm_mday; + _lastSunPositionCalculatedYMD = CALC_UNIQUE_ID; setDoRecalc(false); if (!gotLocalTime) {