Skip to content

Commit

Permalink
Fix sun method. 1.9 broke it.
Browse files Browse the repository at this point in the history
  • Loading branch information
sffjunkie committed Jan 31, 2019
1 parent 196d173 commit 52b0c6a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def read_contents(*names, **kwargs):
long_description = description

setup(name='astral',
version='1.9.1',
version='1.9.2',
description=description,
long_description=long_description,
author='Simon Kennedy',
Expand Down
10 changes: 5 additions & 5 deletions src/astral.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@

__all__ = ["Astral", "Location", "AstralGeocoder", "GoogleGeocoder", "AstralError"]

__version__ = "1.9.1"
__version__ = "1.9.2"
__author__ = "Simon Kennedy <sffjunkie+code@gmail.com>"

SUN_RISING = 1
Expand Down Expand Up @@ -1757,11 +1757,11 @@ def sun_utc(self, date, latitude, longitude, observer_elevation=0):
:rtype: dict
"""

dawn = self.dawn_utc(date, latitude, longitude, observer_elevation)
sunrise = self.sunrise_utc(date, latitude, longitude, observer_elevation)
dawn = self.dawn_utc(date, latitude, longitude, observer_elevation=observer_elevation)
sunrise = self.sunrise_utc(date, latitude, longitude, observer_elevation=observer_elevation)
noon = self.solar_noon_utc(date, longitude)
sunset = self.sunset_utc(date, latitude, longitude, observer_elevation)
dusk = self.dusk_utc(date, latitude, longitude, observer_elevation)
sunset = self.sunset_utc(date, latitude, longitude, observer_elevation=observer_elevation)
dusk = self.dusk_utc(date, latitude, longitude, observer_elevation=observer_elevation)

return {
"dawn": dawn,
Expand Down
2 changes: 1 addition & 1 deletion src/doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __getattr__(cls, name):
project = 'Astral'
author = 'Simon Kennedy'
copyright = '2009-2019, %s' % author
version = '1.9.1'
version = '1.9.2'
release = '1.9'

# Add any Sphinx extension module names here, as strings. They can be extensions
Expand Down
3 changes: 3 additions & 0 deletions src/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ Version History
======== =======================================================================
Version Description
======== =======================================================================
1.9.2 1.9 broke the sun_utc method. Sun UTC calculation passed incorrect
parameter to more specific methods e.g. sunrise, sunset etc.
-------- -----------------------------------------------------------------------
1.9.1 Correct version number in astral.py
-------- -----------------------------------------------------------------------
1.9 Now takes elevation into account.
Expand Down
18 changes: 18 additions & 0 deletions src/test/test_Sun.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ def datetime_almost_equal(datetime1, datetime2, seconds=60):
return abs(sd) <= seconds


def test_Astral_Sun():
a = Astral()
l = a['London']

test_data = {
datetime.date(2015, 12, 1): datetime.datetime(2015, 12, 1, 7, 4),
datetime.date(2015, 12, 2): datetime.datetime(2015, 12, 2, 7, 6),
datetime.date(2015, 12, 3): datetime.datetime(2015, 12, 3, 7, 7),
datetime.date(2015, 12, 12): datetime.datetime(2015, 12, 12, 7, 17),
datetime.date(2015, 12, 25): datetime.datetime(2015, 12, 25, 7, 25),
}

for day, dawn in test_data.items():
dawn = pytz.UTC.localize(dawn)
dawn_utc = a.sun_utc(day, l.latitude, l.longitude)['dawn']
assert datetime_almost_equal(dawn, dawn_utc)


def test_Astral_Dawn_Civil():
a = Astral()
l = a['London']
Expand Down

0 comments on commit 52b0c6a

Please sign in to comment.