From 4022da2ad91371a0fd1f4478d3cdee7a3257e88f Mon Sep 17 00:00:00 2001 From: Marco Heiming Date: Tue, 18 Jan 2022 08:27:00 +0100 Subject: [PATCH] Fix night progress calculation --- apps/circlesclock/app.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/circlesclock/app.js b/apps/circlesclock/app.js index fa1faabf4..7d122954d 100644 --- a/apps/circlesclock/app.js +++ b/apps/circlesclock/app.js @@ -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); } } }