astral
astral copied to clipboard
Sun doesn't set in polar circle
Up in the arctic circle, in July during the midnight sun, when looking for the next sunrise and sunset the next sunrise seems to happen before the next sunset. This shouldn't be possible.
I'm sorry but I don't understand the maths enough to fix it. I think this might be related to the next issue I'm submitting and will link to here.
@Swamp-Ig, it seems that this issue was fixed in version 2.0. You pointed this test case but with v2 it was fixed and the passing test case can be found here. Can you please verify that this issue no longer exists with the latest version, so we can close it?
Hi, sorry I haven't looked at this for a very long time. I seem to remember providing a test case somewhere that demonstrated the issue when I submitted it as part of another submitted issue, it was quite a while ago now though.
@Swamp-Ig You mentioned this test case in https://github.com/sffjunkie/astral/issues/35 and another test case for https://github.com/sffjunkie/astral/issues/36
I think that all other test cases where fixed as well with version 2.
Anyway, the following test demonstrates that this issue doesn't exist anymore:
>>> import astral
>>> import astral.sun
>>> import datetime
>>>
>>> def _next_event(event, observer, date):
... for offset in range(0, 365):
... try:
... return getattr(astral.sun, event)(
... observer, date + datetime.timedelta(days=offset))
... except ValueError:
... pass
...
>>> date = datetime.datetime(2019, 7, 5)
>>> observer = astral.Observer(69.6, 18.8, 0.0)
>>> sunrise = _next_event('sunrise', observer, date)
>>> sunset = _next_event('sunset', observer, date)
>>> sunset < sunrise
True
>>> sunrise
datetime.datetime(2019, 7, 25, 23, 11, 15, 370224, tzinfo=<UTC>)
>>> sunset
datetime.datetime(2019, 7, 25, 22, 34, 55, 924228, tzinfo=<UTC>)
The next sunset is indeed before next sunrise, as expected.
@Swamp-Ig, should we close the issue based on the above results?
I haven't thought about this for well over a year, and I really can't remember much about it as I'm doing other things.
It would seem from what you said yes, but I can't really confirm or deny.
Basically the problem was that on some days in very Northern latitudes, the sun would only set and not rise, or something of that nature. If this isn't happening anymore, then I guess the answer would be yes.