classification
Title: Add ability to get/set tzinfo on datetime instances in C API
Type: enhancement Stage:
Components: C API, Library (Lib) Versions: Python 3.6
process
Status: open Resolution:
Dependencies: 10381 Superseder:
Assigned To: Nosy List: atuining, belopolsky, dlenski, p-ganssle
Priority: normal Keywords:

Created on 2017-04-24 15:27 by atuining, last changed 2019-12-09 16:15 by belopolsky.

Messages (2)
msg292230 - (view) Author: Anthony Tuininga (atuining) * Date: 2017-04-24 15:27
Right now there is no documented way to create a datetime instance with a tzinfo instance. The documented macros all hard code the value Py_None for the tzinfo parameter. Using the PyObject_Call() method instead of the macro for creating a datetime instance is ~5x slower.

In addition, there is no macro or method for getting the tzinfo from an existing datetime instance. Perhaps creating DATE_GET_TZINFO and TIME_GET_TZINFO would be acceptable?

The enhancement 10381 (http://bugs.python.org/issue10381) would also be needed.

I can provide a GitHub PR if that would be helpful. I first want to make sure that such an effort would be appreciated!
msg321112 - (view) Author: Paul Ganssle (p-ganssle) * (Python committer) Date: 2018-07-05 15:54
Hmm. I never noticed this. In the past I have used the (undocumented) PyDateTimeAPI struct, which the official macros wrap. I'm not sure how official that struct is considering it doesn't show up in the documentation.

I agree that it should be possible to construct TZ-aware datetimes using the official C API, so I guess the question is whether to add a bunch more macros or document the existing struct.
History
Date User Action Args
2019-12-09 16:15:45belopolskysetdependencies: + Add timezone support to datetime C API
2019-12-09 16:13:43vstinnersetcomponents: + C API
2018-07-05 15:54:14p-gansslesetnosy: + p-ganssle
messages: + msg321112
2017-04-29 15:56:14xiang.zhangsetnosy: + belopolsky
2017-04-24 16:35:31dlenskisetnosy: + dlenski
2017-04-24 15:27:26atuiningcreate