Evening time calculations fail for greater longitudes.

Bug #554041 reported by Derek_ on 2010-04-02
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Simon Kennedy

Bug Description

import datetime
from astral import Astral
date = datetime.datetime(2010, 4, 2)
a = Astral()
a.sunset_utc(date=date, latitude=32.733, longitude=117.167) # San Diego

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/astral.py", line 938, in sunset_utc
    sunset = datetime.datetime(date.year, date.month, date.day, hour, minute, second, tzinfo=pytz.utc)
ValueError: hour must be in 0..23

The problem is that in the functions xxx_utc, the hours being given to the datetime.datetime constructor have been increased by longitude to more than 23.

This is easily fixed by adding these lines just before the datetime.datetime in each of those functions:
        if hour > 23:
            hour -= 24
            date += datetime.timedelta(days=1)

Related branches

Simon Kennedy (sffjunkie) wrote :

New version 0.2 added to PyPi

Changed in astral:
assignee: nobody → Simon Kennedy (sffjunkie)
importance: Undecided → Medium
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers