Fix sunprogress calculation during night

master
Marco Heiming 2022-01-27 20:18:57 +01:00
parent a0ca017af7
commit 73f9511128
1 changed files with 5 additions and 5 deletions

View File

@ -504,12 +504,12 @@ function getSunProgress() {
}
} else {
// during night
if (sunSet < sunRise) {
const upcomingSunRise = sunRise + 60 * 60 * 24;
return 1 - (upcomingSunRise - now) / (upcomingSunRise - sunSet);
if (now < sunRise) {
const prevSunSet = sunSet - 60 * 60 * 24;
return 1- (sunRise - now) / (sunRise - prevSunSet);
} else {
const lastSunSet = sunSet - 60 * 60 * 24;
return (now - lastSunSet) / (sunRise - lastSunSet);
const upcomingSunRise = sunRise + 60 * 60 * 24;
return (upcomingSunRise - now) / (upcomingSunRise - sunSet);
}
}
}