python-zmanim icon indicating copy to clipboard operation
python-zmanim copied to clipboard

Zmanim vary by time when using a `datetime` object as input

Open hudcap opened this issue 1 year ago • 2 comments

Different times yield different zmanim. MWE:

import datetime as dt
from zmanim.util.geo_location import GeoLocation
from zmanim.zmanim_calendar import ZmanimCalendar
location = GeoLocation('Lakewood, NJ', 40.0721087, -74.2400243, 'America/New_York', elevation=15)
print(ZmanimCalendar(geo_location=location, date=dt.datetime(2023,8,7)).shkia())
print(ZmanimCalendar(geo_location=location, date=dt.datetime(2023,8,7,1)).shkia())

Even worse, when no date is passed, the default is a datetime object with the current time, so

print(ZmanimCalendar(geo_location=location).shkia())

will yield different, incorrect times throughout the day.

As per @pinnymz, ZmanimCalendar should require a date object. While a datetime object can be coerced to a date, since the caller may possibly want the next day's zmanim (e.g., if it's after nightfall), we agreed that the input should be restricted to date object, placing the onus on the caller to decide which date.

PR to follow.

hudcap avatar Aug 07 '23 17:08 hudcap

This will break backwards compatibility, but every datetime object has a date() method that will return a date, so it shouldn't be too difficult to update old code.

@pinnymz Should we allow datetime objects set to midnight, in an attempt to preserve some backwards compatibility?

hudcap avatar Aug 07 '23 17:08 hudcap

The date object is imported from the datetime library, but date is also used as a parameter, which can create problems.

@pinnymz Any objections if I switch to import datetime as dt and then use dt.date, dt.datetime, etc.?

hudcap avatar Aug 07 '23 17:08 hudcap