Skip to content

Commit 73136ea

Browse files
Impl time crate into pyo3 (#5057)
* First draft for implementing time crate into PyO3 * Refactor FromPyObject for PrimitiveDateTime. Disable proptest * Refactor FromPyObject for OffsetDateTime and UtcDateTime * Create extract_date_time function for reusable code * Fix all proptests * Fix doc test * Add changelog * Downgrade time crate version for msrv. Fix clippy error * Remove UtcDateTime * Fix fmt CI failure * Bring back UtcDateTime. Bump time crate to 0.3.38. Add features doc. * Add time feature to noxfile * use timezone_utc. add const SECONDS_PER_DAY. Revise doc example * Fix FromPyObject for UtcDateTime * `intern` only used on limited api --------- Co-authored-by: Icxolu <10486322+Icxolu@users.noreply.github.com>
1 parent 7d166f7 commit 73136ea

File tree

7 files changed

+1535
-5
lines changed

7 files changed

+1535
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ num-bigint = { version = "0.4.2", optional = true }
4545
num-complex = { version = ">= 0.4.6, < 0.5", optional = true }
4646
num-rational = { version = "0.4.1", optional = true }
4747
rust_decimal = { version = "1.15", default-features = false, optional = true }
48+
time = { version = "0.3.38", default-features = false, optional = true }
4849
serde = { version = "1.0", optional = true }
4950
smallvec = { version = "1.0", optional = true }
5051
uuid = { version = "1.11.0", optional = true }

guide/src/features.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,17 @@ Adds a dependency on [num-rational](https://docs.rs/num-rational) and enables co
184184

185185
Adds a dependency on [rust_decimal](https://docs.rs/rust_decimal) and enables conversions into its [`Decimal`](https://docs.rs/rust_decimal/latest/rust_decimal/struct.Decimal.html) type.
186186

187+
### `time`
188+
189+
Adds a dependency on [time](https://docs.rs/time) and requires MSRV 1.67.1. Enables conversions between [time](https://docs.rs/time)'s types and Python:
190+
- [Date](https://docs.rs/time/0.3.38/time/struct.Date.html) -> [`PyDate`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyDate.html)
191+
- [Time](https://docs.rs/time/0.3.38/time/struct.Time.html) -> [`PyTime`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyTime.html)
192+
- [OffsetDateTime](https://docs.rs/time/0.3.38/time/struct.OffsetDateTime.html) -> [`PyDateTime`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyDateTime.html)
193+
- [PrimitiveDateTime](https://docs.rs/time/0.3.38/time/struct.PrimitiveDateTime.html) -> [`PyDateTime`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyDateTime.html)
194+
- [Duration](https://docs.rs/time/0.3.38/time/struct.Duration.html) -> [`PyDelta`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyDelta.html)
195+
- [UtcOffset](https://docs.rs/time/0.3.38/time/struct.UtcOffset.html) -> [`PyTzInfo`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyTzInfo.html)
196+
- [UtcDateTime](https://docs.rs/time/0.3.38/time/struct.UtcDateTime.html) -> [`PyDateTime`]({{#PYO3_DOCS_URL}}/pyo3/types/struct.PyDateTime.html)
197+
187198
### `serde`
188199

189200
Enables (de)serialization of `Py<T>` objects via [serde](https://serde.rs/).

newsfragments/5057.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Integrate `time` crate into PyO3

noxfile.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ def test_rust(session: nox.Session):
101101
if not FREE_THREADED_BUILD:
102102
_run_cargo_test(session, features="abi3")
103103
if "skip-full" not in session.posargs:
104-
_run_cargo_test(session, features="full jiff-02")
104+
_run_cargo_test(session, features="full jiff-02 time")
105105
if not FREE_THREADED_BUILD:
106-
_run_cargo_test(session, features="abi3 full jiff-02")
106+
_run_cargo_test(session, features="abi3 full jiff-02 time")
107107

108108

109109
@nox.session(name="test-py", venv_backend="none")
@@ -429,6 +429,10 @@ def docs(session: nox.Session) -> None:
429429

430430
features = "full"
431431

432+
if get_rust_version()[:2] >= (1, 67):
433+
# time needs MSRC 1.67+
434+
features += ",time"
435+
432436
if get_rust_version()[:2] >= (1, 70):
433437
# jiff needs MSRC 1.70+
434438
features += ",jiff-02"
@@ -819,8 +823,8 @@ def update_ui_tests(session: nox.Session):
819823
env["TRYBUILD"] = "overwrite"
820824
command = ["test", "--test", "test_compile_error"]
821825
_run_cargo(session, *command, env=env)
822-
_run_cargo(session, *command, "--features=full,jiff-02", env=env)
823-
_run_cargo(session, *command, "--features=abi3,full,jiff-02", env=env)
826+
_run_cargo(session, *command, "--features=full,jiff-02,time", env=env)
827+
_run_cargo(session, *command, "--features=abi3,full,jiff-02,time", env=env)
824828

825829

826830
@nox.session(name="test-introspection")
@@ -891,6 +895,10 @@ def _get_feature_sets() -> Generator[Tuple[str, ...], None, None]:
891895
# multiple-pymethods not supported on wasm
892896
features += ",multiple-pymethods"
893897

898+
if get_rust_version()[:2] >= (1, 67):
899+
# time needs MSRC 1.67+
900+
features += ",time"
901+
894902
if get_rust_version()[:2] >= (1, 70):
895903
# jiff needs MSRC 1.70+
896904
features += ",jiff-02"

src/conversions/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ pub mod rust_decimal;
1616
pub mod serde;
1717
pub mod smallvec;
1818
mod std;
19+
pub mod time;
1920
pub mod uuid;

0 commit comments

Comments
 (0)