#chrono #pyo3 #datetime #python

pyo3-chrono

Adds PyO3 support to Chrono structs via newtypes

1 unstable release

0.1.0 Jan 21, 2021

#98 in Date and time

Download history 1/week @ 2021-02-20 7/week @ 2021-02-27 2/week @ 2021-03-06 2/week @ 2021-03-13 2/week @ 2021-03-20 45/week @ 2021-03-27 38/week @ 2021-04-03 39/week @ 2021-04-10 23/week @ 2021-04-17 5/week @ 2021-04-24 12/week @ 2021-05-01 2/week @ 2021-05-08 77/week @ 2021-05-15 49/week @ 2021-05-22 14/week @ 2021-05-29 23/week @ 2021-06-05

62 downloads per month

MIT license

18KB
349 lines

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.

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.


lib.rs:

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.

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

~2MB
~42K SLoC