Open jfbauer432 opened 4 years ago
This is the workaround I am using
def sunset(dt):
sun = Sun(LAT, LON)
ss = sun.get_local_sunset_time(dt)
sr = sun.get_local_sunrise_time(dt)
if ss < sr:
ss = ss + datetime.timedelta(1)
return ss
Just noticed it too. It just smashed an hour of work. >.<
Even when the timezone is set in pandas
(e.g. tz='America/New_York'
), the resulting sunset date is back in utc.
You can force it via:
sun.get_local_sunset_time(dt).replace(tzinfo=pytz.utc).astimezone(pytz.timezone('America/New_York'))
I'll check it thanks for reporting!
Just stumbled across this myself, thanks for the workarounds.
I have a similar issue, but I don't think its related to timezone - when getting sunrise/sunset times 2020 in a single location (long = -83.09, lat = 40.18) the sunset time reverts to a day back on 4/3/2020. ...snip... Sunrise: 1585466400.0 - Sunset: 1585511640.0 - Daylight hr: 12.57 Sunrise: 1585552680.0 - Sunset: 1585598100.0 - Daylight hr: 12.62 Sunrise: 1585639020.0 - Sunset: 1585684560.0 - Daylight hr: 12.65 Sunrise: 1585725300.0 - Sunset: 1585771020.0 - Daylight hr: 12.7 Sunrise: 1585811640.0 - Sunset: 1585857480.0 - Daylight hr: 12.73 Sunrise: 1585897920.0 - Sunset: 1585943940.0 - Daylight hr: 12.78 Sunrise: 1585984200.0 - Sunset: 1585944000.0 - Daylight hr: -11.17 Sunrise: 1586070540.0 - Sunset: 1586030520.0 - Daylight hr: -11.12 Sunrise: 1586156820.0 - Sunset: 1586116980.0 - Daylight hr: -11.07 ...snip... @jfbauer432's solution worked for me.
I just found this issue too. No fix two years later?
Solved in https://github.com/SatAgro/suntime/pull/19
tested using this:
import datetime
import pytz
sun = Sun(38.8895, -77.0353)
tz = pytz.timezone('America/New_York')
day = datetime.datetime(2020, 4, 29, 7, 35, 24, 335561)
day
print(sun.get_sunrise_time(day))
print(sun.get_sunset_time(day))
print("")
print(sun.get_sunrise_time(day, tz=tz))
print(sun.get_sunset_time(day, tz=tz))
sun = Sun(39.8895, -77.0353)
tz = pytz.timezone('America/New_York')
day = datetime.datetime(2020, 4, 29, 7, 35, 24, 335561)
day
print(sun.get_sunrise_time(day))
print(sun.get_sunset_time(day))
print("")
print(sun.get_sunrise_time(day, tz=tz))
print(sun.get_sunset_time(day, tz=tz))
But, it merely change the date. Can you help me confirm my solution @jfbauer432?
Yeah, but the pull request hasn't been merged yet so still no fix. Testing if sunset is before sunrise is still the only valid solution, beside modifying the source on my end,
First, get the sunrise/set times for Washington D.C. These look correct. (www.timeanddate.com report 06:12 and 19:59 for sunrise/set today)
Now change the latitude 1 degree north. A small change is expected, but notice that the sunset time jumps back one day now that the sunset time goes beyond 20:00 local time (00:00 UTC)