Are there any datetime.tzinfo implementations in C?

為{幸葍}努か 提交于 2019-12-13 08:14:35

问题


I've been working on a Python library that uses a C extension module to do ISO 8601 parsing.

Part of that work requires the creation of tzinfo objects, which is by far the slowest part of the parse. Calls out to Python implementations of tzinfo (currently pytz.FixedOffset) are simply too slow.

In Python 3.7, datetime.timezone is finally exposed to the C-API. My code takes adavantage of it, and gets a tremendous performance boost from using a C implementation instead of a Python one. I'd love to find a similar C implementation that I could use for Python < 3.6. Perhaps a "backport" of 3.7's datetime.timezone?

I've seen many Python implementations of tzinfo (pytz, datetuil.tz, django.utils.timezone, psycopg2.tz) but none in C.

Are there C implementations of tzinfo (besides datetime.timezone)?


回答1:


After searching some more, I ended up finding an implementation in Pendulum's low level ISO 8601 parser.

Edit: This implementation was eventually used in my backport of datetime.fromisoformat



来源:https://stackoverflow.com/questions/50336229/are-there-any-datetime-tzinfo-implementations-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!