Skip to content

Comparison between time of transit date and input date does not account for timezone while calculating dawn time #96

@peng-chen-fda

Description

@peng-chen-fda
from datetime import datetime
from astral import LocationInfo
from astral.location import Location
from astral.sun import sun

loc_info = LocationInfo('', '', 'Asia/Kolkata', 10.7655888888889, 78.7150444444444)
loc = Location(loc_info )

time_local = datetime.strptime('2024-05-17 22:34:37', '%Y-%m-%d %H:%M:%S')
s = sun(loc_info .observer, date=time_local .date(), tzinfo=loc .timezone)

Above snippet would result in Unable to find a dawn time on the date specified

The reason is because the initial calculation would give the tot (time of transit) as 2024-05-18 05:29:42.178336+05:30, and then its date (2024-05-18) is used to compare against (2024-05-17), which would adjust the input date to 2024-05-16, thus the ValueError.

Proposed solution: the initial date comparison between tot and input date should account for timezone.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions