Giter Club home page Giter Club logo

pyo3-chrono's Introduction

THIS CRATE IS DEPRECATED

PyO3 0.17.2 added native support for chrono in PyO3/pyo3#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.

pyo3-chrono's People

Contributors

kangalio avatar dependabot[bot] avatar msurkovsky avatar

Stargazers

Ivan Smirnov avatar  avatar Kindritskiy Maksym avatar Andrey Grazhdankov avatar Todd Young avatar Shailendra Sharma avatar fx-kirin avatar Hassan Ghannoum avatar  amin jamal avatar Seonu Jang avatar Flare avatar Samuel Colvin avatar Daniil Konovalenko avatar Patrik Gebhardt avatar  avatar Miles Granger avatar

Watchers

James Cloos avatar  avatar

Forkers

snow01 msurkovsky

pyo3-chrono's Issues

Add compile errors for abi3 builds

This crate depends on traits that state Available on non-Py_LIMITED_API only. This basically means that pyo3 must not have the abi3 feature enabled as far as I understand it, but my knowledge here is limited.

If there is a good reason for this, I would propose to at least add compile_error! macros to the crate because now I was left a bit stumped when the compilation of pyo3-chrono failed with 10 errors about non-existing types from pyo3.

An example of the error (there are more but basically the same with different types):

error[E0432]: unresolved imports `pyo3::types::PyDateAccess`, `pyo3::types::PyDeltaAccess`, `pyo3::types::PyTimeAccess`
  --> ...\.cargo\registry\src\github.com-1ecc6299db9ec823\pyo3-chrono-0.5.0\src\lib.rs:33:19
   |
33 | use pyo3::types::{PyDateAccess as _, PyDeltaAccess as _, PyTimeAccess as _};
   |                   ^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^ no `PyTimeAccess` in `types`
   |                   |                  |
   |                   |                  no `PyDeltaAccess` in `types`
   |                   no `PyDateAccess` in `types`

Support serde's Serialize and Deserialize

Hey, chrono has support for serde built in but using this crate you lose that support. I think it'd be cool for this crate to support a feature flag for this purpose so that if you had a serialize NaiveDateTime before it can still be automatically derived.

How to convert PyDateTime to DateTime<Utc>

How do I convert from a &PyDateTime parameter ? to DateTime

I currently have

let naive_start: NaiveDateTime = start_datetime.extract::<NaiveDateTime>().unwrap();
let start = DateTime::<Utc>::from_utc(naive_start, Utc);

but I keep getting the error


the trait bound `NaiveDateTime: PyClass` is not satisfied
   --> src/bmos-scheduler.rs:366:57
    |
366 |         let naive_start: NaiveDateTime = start_datetime.extract::<NaiveDateTime>().unwrap();
    |                                                         ^^^^^^^ the trait `PyClass` is not implemented for `NaiveDateTime`
    |
    = note: required because of the requirements on the impl of `pyo3::FromPyObject<'_>` for `NaiveDateTime`

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.