You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
Below is the quick workaround I tried that seems to work for me and for your test case above - but I am not confident enough to put in a PR:
File: astral/moon.py
Line: 424 @@ def moonrise(
info=riseset(date, observer)
#ADDEDifnotinfo[0]:
# TRICKY: date is based on UTC so it might not return a value for the current date/time if non-UTC so back up 1 day if Nonedelta=datetime.timedelta(days=-1)
new_date=date+deltainfo=riseset(new_date, observer)
#ADDEDifinfo[0]:
Line 476 @@ def moonset(
info=riseset(date, observer)
#ADDEDifnotinfo[1]:
# TRICKY: date is based on UTC so it might not return a value for the current UTC date/time if non-UTC so go forward 1 day if Nonedelta=datetime.timedelta(days=1)
new_date=date+deltainfo=riseset(new_date, observer)
#ADDEDifinfo[0]:
I think #88 is related. I do like and appreciate this lightweight library - it has been helpful and very easy to use and deploy.
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:
The text was updated successfully, but these errors were encountered: