diff --git a/include/SunPosition.h b/include/SunPosition.h index 05e3b3969..26caab7b7 100644 --- a/include/SunPosition.h +++ b/include/SunPosition.h @@ -22,7 +22,6 @@ class SunPositionClass { bool getDoRecalc(); SunSet _sun; - bool _isDayPeriod = true; bool _isSunsetAvailable = true; uint32_t _sunriseMinutes = 0; uint32_t _sunsetMinutes = 0; diff --git a/src/SunPosition.cpp b/src/SunPosition.cpp index 7044ae485..0d4d419ba 100644 --- a/src/SunPosition.cpp +++ b/src/SunPosition.cpp @@ -26,7 +26,14 @@ void SunPositionClass::loop() bool SunPositionClass::isDayPeriod() { - return _isDayPeriod; + if (!_isValidInfo) { + return true; + } + + struct tm timeinfo; + getLocalTime(&timeinfo, 5); + uint32_t minutesPastMidnight = timeinfo.tm_hour * 60 + timeinfo.tm_min; + return (minutesPastMidnight >= _sunriseMinutes) && (minutesPastMidnight < _sunsetMinutes); } bool SunPositionClass::isSunsetAvailable() @@ -73,7 +80,6 @@ void SunPositionClass::updateSunData() setDoRecalc(false); if (!gotLocalTime) { - _isDayPeriod = true; _sunriseMinutes = 0; _sunsetMinutes = 0; _isValidInfo = false; @@ -108,7 +114,6 @@ void SunPositionClass::updateSunData() // If no sunset/sunrise exists (e.g. astronomical calculation in summer) // assume it's day period if (std::isnan(sunriseRaw) || std::isnan(sunsetRaw)) { - _isDayPeriod = true; _isSunsetAvailable = false; _sunriseMinutes = 0; _sunsetMinutes = 0; @@ -118,9 +123,7 @@ void SunPositionClass::updateSunData() _sunriseMinutes = static_cast(sunriseRaw); _sunsetMinutes = static_cast(sunsetRaw); - uint32_t minutesPastMidnight = timeinfo.tm_hour * 60 + timeinfo.tm_min; - _isDayPeriod = (minutesPastMidnight >= _sunriseMinutes) && (minutesPastMidnight < _sunsetMinutes); _isSunsetAvailable = true; _isValidInfo = true; }