From 6d639f00083afdbb8d4fb0f1c9eda3ac8c122aa4 Mon Sep 17 00:00:00 2001 From: Peter Hinch Date: Fri, 29 Dec 2023 11:17:07 +0000 Subject: [PATCH] astronomy: RiSet fix bug in .has_risen() and .has_set(). --- astronomy/sun_moon.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/astronomy/sun_moon.py b/astronomy/sun_moon.py index a4f8eca..de6fe87 100644 --- a/astronomy/sun_moon.py +++ b/astronomy/sun_moon.py @@ -243,20 +243,22 @@ class RiSet: self.lto = round(t * 3600) # Localtime offset in secs def has_risen(self, sun: bool): - now = round(time.time()) + self.lto # UTC - rt = self.sunrise(1) if sun else self.moonrise(1) + now = round(time.time()) # Machine time + rt = self.sunrise(1) if sun else self.moonrise(1) # Machine time if rt is None: + now += self.lto # UTC t = (now % 86400) / 3600 # Time as UTC hour of day (float) return self.sin_alt(t, sun) > 0 # Above horizon return rt < now def has_set(self, sun: bool): - now = round(time.time()) + self.lto # UTC + now = round(time.time()) st = self.sunset(1) if sun else self.moonset(1) if st is None: + now += self.lto # UTC t = (now % 86400) / 3600 # Time as UTC hour of day (float) return self.sin_alt(t, sun) < 0 - return st > now + return st < now def is_up(self, sun: bool): # Return current state of sun or moon return self.has_risen(sun) and not self.has_set(sun)