Expand description
Conversions to and from chrono-tz’s Tz.
This feature requires at least Python 3.9.
§Setup
To use this feature, add this to your Cargo.toml:
[dependencies]
chrono-tz = "0.8"
pyo3 = { version = "0.27.1", features = ["chrono-tz"] }Note that you must use compatible versions of chrono, chrono-tz and PyO3. The required chrono version may vary based on the version of PyO3.
§Example: Convert a zoneinfo.ZoneInfo to chrono-tz’s Tz
use chrono_tz::Tz;
use pyo3::{Python, PyResult, IntoPyObject, types::PyAnyMethods};
fn main() -> PyResult<()> {
Python::initialize();
Python::attach(|py| {
// Convert to Python
let py_tzinfo = Tz::Europe__Paris.into_pyobject(py)?;
// Convert back to Rust
assert_eq!(py_tzinfo.extract::<Tz>()?, Tz::Europe__Paris);
Ok(())
})
}