Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparison between time of transit date and input date does not account for timezone while calculating dawn time #96

Open
peng-chen-fda opened this issue Oct 2, 2024 · 1 comment

Comments

@peng-chen-fda
Copy link

from datetime import datetime
from astral import LocationInfo
from astral.location import Location
from astral.sun import sun

loc_info = LocationInfo('', '', 'Asia/Kolkata', 10.7655888888889, 78.7150444444444)
loc = Location(loc_info )

time_local = datetime.strptime('2024-05-17 22:34:37', '%Y-%m-%d %H:%M:%S')
s = sun(loc_info .observer, date=time_local .date(), tzinfo=loc .timezone)

Above snippet would result in Unable to find a dawn time on the date specified

The reason is because the initial calculation would give the tot (time of transit) as 2024-05-18 05:29:42.178336+05:30, and then its date (2024-05-18) is used to compare against (2024-05-17), which would adjust the input date to 2024-05-16, thus the ValueError.

Proposed solution: the initial date comparison between tot and input date should account for timezone.

@peng-chen-fda
Copy link
Author

peng-chen-fda commented Oct 25, 2024

The question is - is it possible that the caller actually wants to find the dawn by rolling to further past? I understand the steps is to to calculate the time of transit by rolling forward, but is there a set of steps to follow to roll back further to find the time of transit instead which can be offered as option to function caller? That can potentially help with such detection in the aforementioned corner case.

current steps to adjust offset - if the offset exceeds half a day in the past, then it would roll forward a day:

astral/src/astral/sun.py

Lines 316 to 317 in ac23ab5

if offset < -720.0:
offset += 1440

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant