#chrono #pyo3 #date-time #python #api-bindings #wrapper

pyo3-chrono

Adds PyO3 support to Chrono structs via newtypes

8 releases (4 breaking)

0.5.1 Jan 18, 2023
0.5.0 Aug 24, 2022
0.4.0 Mar 1, 2022
0.3.0 Nov 4, 2021
0.1.0 Jan 21, 2021

#287 in Date and time

Download history 203/week @ 2024-03-14 207/week @ 2024-03-21 236/week @ 2024-03-28 363/week @ 2024-04-04 271/week @ 2024-04-11 111/week @ 2024-04-18 55/week @ 2024-04-25 64/week @ 2024-05-02 41/week @ 2024-05-09 84/week @ 2024-05-16 53/week @ 2024-05-23 414/week @ 2024-05-30 44/week @ 2024-06-06 53/week @ 2024-06-13 56/week @ 2024-06-20 24/week @ 2024-06-27

189 downloads per month
Used in puff-rs

MIT license

18KB
318 lines

THIS CRATE IS DEPRECATED

PyO3 0.17.2 added native support for chrono in https://github.com/PyO3/pyo3/pull/2612 behind the chrono feature flag. You shouldn't use this crate anymore.

pyo3-chrono

This crate provides newtype wrappers around chrono's NaiveDateTime, NaiveDate, NaiveTime, and Duration structs, that can be used in PyO3 applications.

Leap seconds are handled correctly, however timezones are not supported because Python itself doesn't inherently support timezones in its datetimes.

Implementations for the serde::Serialize and serde::Deserialize traits can be enabled via the serde feature flag.

Truncation

Python can store durations from negative one billion days up to positive one billion days long, in microsecond precision. However, Chrono only accepts microseconds as i64:

Python's max duration: 84599999999999999999 microseconds
Chrono's max duration: 9223372036854775807 microseconds

Python's min duration: -84599999915400000000 microseconds
Chrono's min duration: -9223372036854775808 microseconds

As you can see, Chrono doesn't support the entire range of durations that Python supports. When encountering durations that are unrepresentable in Chrono, this library truncates the duration to the nearest supported duration.

Dependencies

~3.5–9MB
~76K SLoC