suncalc-py icon indicating copy to clipboard operation
suncalc-py copied to clipboard

Wrong annotations are misleading

Open Hcreak opened this issue 3 years ago • 2 comments

date (datetime or a pandas series of datetimes): date and time to find sunlight phases of. Datetime must be in UTC.

This comment made me use datetime.utcnow() incorrectly. And actually need to pass the local time like in your example code using datetime.now()

Hcreak avatar Sep 15 '22 10:09 Hcreak

This is a great library, and thank you so much for making it available!

I too have been confused by the use of time zones. While the text above says that the datetime must be UTC, I agree that it seems to require a local time.

But the use of time zones is inconsistent. The time returned by get_times() -- e.g., sunset -- is indeed in UTC. Calculating the solar altitude at the computed sunset time should be zero, but it is not that way. Am I mis-understanding the time zone usage?

 lon = 80        # Position [deg] for Sri Lanka, GMT + 5.5
 lat = 7    
 offset = timedelta(seconds=3600*5.5)       # Offset from UTC to local time
 date = datetime.now()
 get_position(get_times(date, lon, lat)['sunset'], lon, lat)          # Incorrect result: altitude 1.37 radians
 get_position(get_times(date, lon, lat)['sunset'] + offset, lon, lat) # Correct result:   altitude ~0 radians

henrythroop avatar Mar 21 '23 08:03 henrythroop

This was intended to be a direct port of suncalc. I don't remember how the UTC/time zone behavior works/is supposed to work. I haven't been using this lately, but PRs are welcome

kylebarron avatar Mar 21 '23 15:03 kylebarron