C中是否有任何datetime.tzinfo实现? [英] Are there any datetime.tzinfo implementations in C?

查看:106
本文介绍了C中是否有任何datetime.tzinfo实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究使用C扩展模块进行ISO 8601解析的Python库.

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

其中一部分工作需要创建tzinfo对象,这是迄今为止解析最慢的部分.调用tzinfo(当前为pytz.FixedOffset)的Python实现太慢了.

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.

在Python 3.7中,datetime.timezone最终暴露给C-API.我的代码对此进行了改进,并通过使用C实现而不是Python实现极大地提高了性能.我很想找到一个可用于Python<的类似C实现. 3.6.也许是3.7的datetime.timezone的反向移植"?

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?

我见过tzinfo的许多Python实现(pytzdatetuil.tzdjango.utils.timezonepsycopg2.tz),但是在C语言中却没有.

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

除了datetime.timezone之外,还有tzinfo的C实现吗?

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

推荐答案

在搜索了更多内容之后,我最终在 ISO 8601解析器.

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

该实现最终用于我对datetime.fromisoformat

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

这篇关于C中是否有任何datetime.tzinfo实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆