-
Notifications
You must be signed in to change notification settings - Fork 40
Open
Description
$ pip3 show suntime | grep Version
Version: 1.2.5
$ python3
Python 3.7.5 (default, Apr 19 2020, 20:18:17)
[GCC 9.2.1 20191008] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> import pytz
>>> from suntime import Sun
>>>
>>> tz = pytz.timezone('America/New_York')
>>> tz
<DstTzInfo 'America/New_York' LMT-1 day, 19:04:00 STD>
>>>
>>> dt = datetime.datetime.now(tz=tz)
>>> dt
datetime.datetime(2020, 4, 29, 7, 35, 24, 335561, tzinfo=<DstTzInfo 'America/New_York' EDT-1 day, 20:00:00 DST>)
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)
>>> sun = Sun(38.8895, -77.0353)
>>> sun.get_local_sunrise_time(dt)
datetime.datetime(2020, 4, 29, 6, 12, tzinfo=tzlocal())
>>> sun.get_local_sunset_time(dt)
datetime.datetime(2020, 4, 29, 19, 59, tzinfo=tzlocal())
>>> sun.get_sunrise_time(dt)
datetime.datetime(2020, 4, 29, 10, 12, tzinfo=tzutc())
>>> sun.get_sunset_time(dt)
datetime.datetime(2020, 4, 29, 23, 59, tzinfo=tzutc())
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)
>>> sun = Sun(39.8895, -77.0353)
>>> sun.get_local_sunrise_time(dt)
datetime.datetime(2020, 4, 29, 6, 10, tzinfo=tzlocal())
>>> sun.get_local_sunset_time(dt)
datetime.datetime(2020, 4, 28, 20, 1, tzinfo=tzlocal()) <=== Wrong, should be the 29th
>>> sun.get_sunrise_time(dt)
datetime.datetime(2020, 4, 29, 10, 10, tzinfo=tzutc())
>>> sun.get_sunset_time(dt)
datetime.datetime(2020, 4, 29, 0, 1, tzinfo=tzutc()) <==== Wrong, should be the 30th
Metadata
Metadata
Assignees
Labels
No labels