Skip to content

Commit 42324a3

Browse files
Add test
1 parent 1456bc1 commit 42324a3

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/conversions/chrono.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,35 @@ mod tests {
11841184
})
11851185
}
11861186

1187+
#[test]
1188+
#[cfg(all(Py_3_9, feature = "chrono-tz", not(windows)))]
1189+
fn test_pyo3_datetime_into_pyobject_tz() {
1190+
Python::with_gil(|py| {
1191+
let datetime = NaiveDate::from_ymd_opt(2024, 12, 11)
1192+
.unwrap()
1193+
.and_hms_opt(23, 03, 13)
1194+
.unwrap()
1195+
.and_local_timezone(chrono_tz::Tz::Europe__London)
1196+
.unwrap();
1197+
let datetime = datetime.into_pyobject(py).unwrap();
1198+
let py_datetime = new_py_datetime_ob(
1199+
py,
1200+
"datetime",
1201+
(
1202+
2024,
1203+
12,
1204+
11,
1205+
23,
1206+
03,
1207+
13,
1208+
0,
1209+
python_zoneinfo(py, "Europe/London"),
1210+
),
1211+
);
1212+
assert_eq!(datetime.compare(&py_datetime).unwrap(), Ordering::Equal);
1213+
})
1214+
}
1215+
11871216
#[test]
11881217
fn test_pyo3_datetime_frompyobject_utc() {
11891218
Python::with_gil(|py| {
@@ -1387,6 +1416,16 @@ mod tests {
13871416
.unwrap()
13881417
}
13891418

1419+
#[cfg(Py_3_9)]
1420+
fn python_zoneinfo<'py>(py: Python<'py>, timezone: &str) -> Bound<'py, PyAny> {
1421+
py.import("zoneinfo")
1422+
.unwrap()
1423+
.getattr("ZoneInfo")
1424+
.unwrap()
1425+
.call1((timezone,))
1426+
.unwrap()
1427+
}
1428+
13901429
#[cfg(not(any(target_arch = "wasm32", Py_GIL_DISABLED)))]
13911430
mod proptests {
13921431
use super::*;

0 commit comments

Comments
 (0)