Skip to content

datetime: support timezone bindings#1588

Merged
davidhewitt merged 1 commit intoPyO3:mainfrom
davidhewitt:timezone_offset
Jul 13, 2022
Merged

datetime: support timezone bindings#1588
davidhewitt merged 1 commit intoPyO3:mainfrom
davidhewitt:timezone_offset

Conversation

@davidhewitt
Copy link
Member

This PR implements safe wrappers for the Python 3.7 timezone bindings described in #207.

Rather than try to do anything complicated with a new type representing exactly datetime.timezone, I return &PyTzInfo from the three new functions timezone_utc(), timezone_from_offset() and timezone_from_offset_and_name(). I think this is good enough to be useful; datetime.timezone is a subclass of datetime.tzinfo so doing this is correct.

I also adjusted a few constructors taking tzinfo arguments to take Option<&PyTzInfo> instead of Option<&PyObject>.

Finally, I tweaked the ffi symbol PyDateTime_TimeZone_UTC I added recently in #1573 to resolve to &'static *mut ffi::PyObject, which I think is a more correct representation of the "unsafe ffi" nature of that global.

Closes #207

cc @pganssle in case you might be interested / have an opinion on this.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Python 3.7 timezone in datetime bindings

3 participants