File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -1184,6 +1184,35 @@ mod tests {
1184
1184
} )
1185
1185
}
1186
1186
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
+
1187
1216
#[ test]
1188
1217
fn test_pyo3_datetime_frompyobject_utc ( ) {
1189
1218
Python :: with_gil ( |py| {
@@ -1387,6 +1416,16 @@ mod tests {
1387
1416
. unwrap ( )
1388
1417
}
1389
1418
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
+
1390
1429
#[ cfg( not( any( target_arch = "wasm32" , Py_GIL_DISABLED ) ) ) ]
1391
1430
mod proptests {
1392
1431
use super :: * ;
You can’t perform that action at this time.
0 commit comments