SatAgro / suntime

Simple sunset and sunrise time calculation python library.
GNU Lesser General Public License v3.0
110 stars 39 forks source link

get_local_sunrise_time() returns UTC sunrise time. #23

Open jeremyjjbrown opened 1 year ago

jeremyjjbrown commented 1 year ago
>>> from suntime import Sun
>>>
>>> latitude = 43
>>> longitude = -88
>>>
>>> sun = Sun(latitude, longitude)
>>>
>>> today_sr = sun.get_local_sunrise_time()
>>> today_ss = sun.get_local_sunset_time()
>>> print(today_sr)
2023-12-01 13:03:00+00:00
>>> print(today_ss)
2023-12-01 22:18:00+00:00
>>>
>>> today_sr = sun.get_sunrise_time()
>>> today_ss = sun.get_sunset_time()
>>> print(today_sr)
2023-12-01 13:03:00+00:00
>>> print(today_ss)
2023-12-01 22:18:00+00:00
otanner commented 11 months ago

Is your local timezone set to UTC?

>>> import time
>>> time.tzname
('EET', 'EEST')

>>> from suntime import Sun
>>> sun = Sun(43, -88)

>>> sun.get_local_sunrise_time()
datetime.datetime(2024, 1, 3, 15, 24, tzinfo=tzlocal())
>>> sun.get_local_sunrise_time().tzname()
'EET'

>>> sun.get_sunrise_time()
datetime.datetime(2024, 1, 3, 13, 24, tzinfo=tzutc())
>>> sun.get_sunrise_time().tzname()
'UTC'
buelowp commented 8 months ago

You can also just use time_zone=tz.gettz('US/Central') when you call the functions to get the correct timezone.

piperfw commented 5 months ago

My local timezone is set to ('GMT', 'BST') but get_local_sunrise_time() gives the time in UTC (which is equal to GMT but not BST).

sun.get_local_sunrise_time().tzname returns None

Ah, I see this function is being deprecated.

This seems to be a reliable drop-in for me


get_local_sunrise_time = lambda: sun.get_sunrise_time(
        time_zone=datetime.datetime.now().astimezone().tzinfo)