Skip to content

Commit

Permalink
Fix: Take DST into account when recalculating the sunrise sunset time
Browse files Browse the repository at this point in the history
If it is not considered the correct sunset / sunrise time is only calculated at the next day

Fixes: tbnobody#2377
  • Loading branch information
tbnobody committed Oct 27, 2024
1 parent 4594bcb commit 225cab6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/SunPosition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "Utils.h"
#include <Arduino.h>

#define CALC_UNIQUE_ID (((timeinfo.tm_year << 9) | (timeinfo.tm_mon << 5) | timeinfo.tm_mday) << 1 | timeinfo.tm_isdst)

SunPositionClass SunPosition;

SunPositionClass::SunPositionClass()
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down

0 comments on commit 225cab6

Please sign in to comment.