this morning (2024-02-01) I found my solution displaying an error as it could not determine the moon rise for today nor for tomorrow so after a bit of investigation I wrote the following test to show that there seems to be a problem with the moon rise time in situations where UTC has a rise but CET does not. Further this also shows inconsistent behavior (None vs. exception) when there is no moon rise
from astral import LocationInfo
from astral.moon import moonrise, moonset
from datetime import datetime, timedelta, timezone, tzinfo, date
# https://www.timeanddate.com/astronomy/uk/london
city1 = LocationInfo("London", "England", "Europe/London", 51.5, -0.116)
# https://www.timeanddate.com/astronomy/switzerland/zurich
city2 = LocationInfo("Zurich", "Switzerland", "Europe/Zurich", 47.37, 8.54)
test = ({"city":city1, "tz":"Europe/London", "should": None, "date":date(2024,2,1)}
,{"city":city1, "tz":"Europe/London", "should": "00:20", "date":date(2024,2,2)}
,{"city":city1, "tz":"Europe/London", "should": "01:36", "date":date(2024,2,3)}
,{"city":city2, "tz":"Europe/Zurich", "should": None, "date":date(2024,2,1)}
,{"city":city2, "tz":"Europe/Zurich", "should": "00:34", "date":date(2024,2,2)}
,{"city":city2, "tz":"Europe/Zurich", "should": "01:44", "date":date(2024,2,3)}
)
for x in test:
try:
mr = moonrise(x['city'].observer, date=x['date'], tzinfo=x['tz'])
if mr:
print(f'moon rise on {x["date"].strftime("%Y.%m.%d")} in {x["tz"]} (should be {x["should"]}): {mr.strftime("%H:%M")}')
else:
print(f'moon rise on {x["date"].strftime("%Y.%m.%d")} in {x["tz"]} (should be {x["should"]}): None')
except Exception as e:
print(f'moon rise on {x["date"].strftime("%Y.%m.%d")} in {x["tz"]} (should be {x["should"]}): exception: {e}')
moon rise on 2024.02.01 in Europe/London (should be None): exception: Moon never rises on this date, at this location
moon rise on 2024.02.02 in Europe/London (should be 00:20): 00:21
moon rise on 2024.02.03 in Europe/London (should be 01:36): 01:36
moon rise on 2024.02.01 in Europe/Zurich (should be None): None
moon rise on 2024.02.02 in Europe/Zurich (should be 00:34): exception: Moon never rises on this date, at this location
moon rise on 2024.02.03 in Europe/Zurich (should be 01:44): 01:45
this morning (2024-02-01) I found my solution displaying an error as it could not determine the moon rise for today nor for tomorrow so after a bit of investigation I wrote the following test to show that there seems to be a problem with the moon rise time in situations where UTC has a rise but CET does not. Further this also shows inconsistent behavior (None vs. exception) when there is no moon rise
the should-be I've taken from https://www.timeanddate.com/astronomy
and here's the output: