1+ use pyo3:: exceptions:: PyValueError ;
12use pyo3:: intern;
23use pyo3:: prelude:: * ;
34use pyo3:: types:: { PyDict , PyString } ;
45
56use pyo3:: IntoPyObjectExt ;
6- use speedate:: Time ;
7+ use speedate:: { MicrosecondsPrecisionOverflowBehavior , Time } ;
78
89use crate :: build_tools:: is_strict;
910use crate :: errors:: { ErrorType , ValError , ValResult } ;
10- use crate :: input:: { EitherTime , Input } ;
11- use crate :: tools:: SchemaDict ;
11+ use crate :: input:: Input ;
1212
1313use super :: datetime:: extract_microseconds_precision;
1414use super :: datetime:: TZConstraint ;
@@ -18,7 +18,7 @@ use super::{BuildValidator, CombinedValidator, DefinitionsBuilder, ValidationSta
1818pub struct TimeValidator {
1919 strict : bool ,
2020 constraints : Option < TimeConstraints > ,
21- microseconds_precision : speedate :: MicrosecondsPrecisionOverflowBehavior ,
21+ microseconds_precision : MicrosecondsPrecisionOverflowBehavior ,
2222}
2323
2424impl BuildValidator for TimeValidator {
@@ -86,9 +86,14 @@ impl Validator for TimeValidator {
8686 }
8787}
8888
89- fn convert_pytime ( schema : & Bound < ' _ , PyDict > , field : & Bound < ' _ , PyString > ) -> PyResult < Option < Time > > {
90- match schema. get_as ( field) ? {
91- Some ( date) => Ok ( Some ( EitherTime :: Py ( date) . as_raw ( ) ?) ) ,
89+ fn convert_pytime ( schema : & Bound < ' _ , PyDict > , key : & Bound < ' _ , PyString > ) -> PyResult < Option < Time > > {
90+ match schema. get_item ( key) ? {
91+ Some ( value) => match value. validate_time ( false , MicrosecondsPrecisionOverflowBehavior :: default ( ) ) {
92+ Ok ( v) => Ok ( Some ( v. into_inner ( ) . as_raw ( ) ?) ) ,
93+ Err ( _) => Err ( PyValueError :: new_err ( format ! (
94+ "'{key}' must be coercible to a time instance" ,
95+ ) ) ) ,
96+ } ,
9297 None => Ok ( None ) ,
9398 }
9499}
0 commit comments