Fix night progress calculation

pull/1301/head
Marco Heiming 2022-01-18 08:27:00 +01:00
parent 9f3480d7a4
commit 4022da2ad9
1 changed files with 5 additions and 5 deletions

View File

@ -456,7 +456,7 @@ function getSunProgress() {
const sunSet = Math.round(times.sunset.getTime() / 1000);
if (isDay()) {
// during day, progress until sunSet
// during day
const dayLength = sunSet - sunRise;
if (now > sunRise) {
return (now - sunRise) / dayLength;
@ -464,13 +464,13 @@ function getSunProgress() {
return (sunRise - now) / dayLength;
}
} else {
// during night, progress until sunrise:
if (now > sunRise) {
// after sunRise
// during night
if (sunSet < sunRise) {
const upcomingSunRise = sunRise + 60 * 60 * 24;
return 1 - (upcomingSunRise - now) / (upcomingSunRise - sunSet);
} else {
return (sunRise - now) / (sunRise - sunSet);
const lastSunSet = sunSet - 60 * 60 * 24;
return (now - lastSunSet) / (sunRise - lastSunSet);
}
}
}