Fixing current forecast

This commit is contained in:
2026-06-24 16:31:07 -04:00
parent c783a79414
commit f377d0b1c8

View File

@@ -175,8 +175,10 @@ export async function get24HourForecast(currentSensors) {
// Second pass — apply solar heating now that we have sun_elevation per slot
for (const slot of enriched) {
if (slot.sunrise && slot.sunset) {
const t = new Date(slot.time).getTime();
slot.daytime = t >= new Date(slot.sunrise).getTime() && t < new Date(slot.sunset).getTime();
const t = slot.time instanceof Date ? slot.time.getTime() : new Date(slot.time).getTime();
const rise = slot.sunrise instanceof Date ? slot.sunrise.getTime() : new Date(slot.sunrise).getTime();
const set = slot.sunset instanceof Date ? slot.sunset.getTime() : new Date(slot.sunset).getTime();
slot.daytime = t >= rise && t < set;
} else {
slot.daytime = (slot.sun_elevation ?? 0) > 0;
}