0.8.1 solar_elevation doesn't seem to honor DST

Asked by G Allen on 2015-09-30

The following code works as expected with astral 0.7.4. That is, solar_elevation is about -0.3 degrees at sunrise, whether or not daylight savings time is in effect.

However, with astral 0.8.1, solar_elevation is about 10 degrees at sunrise when daylight savings is in effect. It is correct for standard time.

from astral import *
from datetime import date

a = Astral()
location = a['Denver']
d = date(2015, 10, 31) # on DST
sunriseDateAndTime = location.sunrise(local=True, date=d)
sunriseElevation = location.solar_elevation(sunriseDateAndTime)
print 'Sunrise:', sunriseDateAndTime,'Sunrise Elevation: ', sunriseElevation

d = date(2015, 11, 1) # off DST
sunriseDateAndTime = location.sunrise(local=True, date=d)
sunriseElevation = location.solar_elevation(sunriseDateAndTime)
print 'Sunrise:', sunriseDateAndTime,'Sunrise Elevation: ', sunriseElevation

Is this a bug? If not, how do I get around it?

Thanks!

Question information

Language:
English Edit question
Status:
Answered
For:
astral Edit question
Assignee:
No assignee Edit question
Last query:
2015-09-30
Last reply:
2015-12-14
Launchpad Janitor (janitor) said : #1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Simon Kennedy (sffjunkie) said : #2

Yes, that is a bug. Apparently it's some weirdness between pytz and using the .replace method on a datetime object when there are DST changes involved. Code using pytz should use the localize method both in your code and within the astral code. So there are changes that need to be made to the astral code.

Update should be in 0.8.2

Can you help with this problem?

Provide an answer of your own, or ask G Allen for more information if necessary.

To post a message you must log in.