-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timezone ignored in intervals()
#28
Comments
Hi! Thanks for your feedback. I don't think it would be a good idea to add a timezone by default: it will be error prone because most of the time these opening hours fields come from OSM or equivalent and depend on the locality of the point of interest, not of the locality of the user. However I agree that something opt-in may be relevant, mostly because timezone management is always a pain and anything that can make it easier will probably make it welcome (maybe just allow to pass a timezone to the parser so that it outputs times in given timezone). |
Hi, thanks for getting back. I agree with your idea of having the option to pass in a timezone and have whatever datetime objects that are yielded be in that timezone |
Hello! I've just added this while relying on PyO3's conversion layer for timezones, which currently has a few limitations :
Anyway, your example, very slightly modified now works : >> from opening_hours import OpeningHours
>> from datetime import datetime, timedelta
>> from zoneinfo import ZoneInfo
>> oh = OpeningHours('Mo-Fr 09:00-17:00')
>> start = datetime(2022, 9, 5, 0, 0, 0, 0, ZoneInfo("UTC"))
>> end = start + timedelta(days=2)
>> next(oh.intervals(start, end))
(datetime.datetime(2022, 9, 5, 0, 0, tzinfo=datetime.timezone.utc), datetime.datetime(2022, 9, 5, 9, 0, tzinfo=datetime.timezone.utc), State.CLOSED, []) I've played a bit around it and this comes with a few more features :
|
When passing timezone-aware
start
and/orend
to the.intervals()
function the returned datetime objects are not timezone aware:So in the above if you were to do something like the below you would get a Python
TypeError
when doing inequalities, or a False when comparing equality:My Rust isn't good enough to help with the debugging in the code, but it looks like there is not a way to add the timezone cleanly to
NaiveDateTime
?If not it will be possible to do the timezone adjustments on the returned dates in Python, but it would be cool if this was handled straight out of the box.
The text was updated successfully, but these errors were encountered: