1
+ use pyo3:: exceptions:: PyValueError ;
1
2
use pyo3:: intern;
2
3
use pyo3:: prelude:: * ;
3
4
use pyo3:: types:: { PyDict , PyString } ;
4
5
5
6
use pyo3:: IntoPyObjectExt ;
6
- use speedate:: Time ;
7
+ use speedate:: { MicrosecondsPrecisionOverflowBehavior , Time } ;
7
8
8
9
use crate :: build_tools:: is_strict;
9
10
use crate :: errors:: { ErrorType , ValError , ValResult } ;
10
- use crate :: input:: { EitherTime , Input } ;
11
- use crate :: tools:: SchemaDict ;
11
+ use crate :: input:: Input ;
12
12
13
13
use super :: datetime:: extract_microseconds_precision;
14
14
use super :: datetime:: TZConstraint ;
@@ -18,7 +18,7 @@ use super::{BuildValidator, CombinedValidator, DefinitionsBuilder, ValidationSta
18
18
pub struct TimeValidator {
19
19
strict : bool ,
20
20
constraints : Option < TimeConstraints > ,
21
- microseconds_precision : speedate :: MicrosecondsPrecisionOverflowBehavior ,
21
+ microseconds_precision : MicrosecondsPrecisionOverflowBehavior ,
22
22
}
23
23
24
24
impl BuildValidator for TimeValidator {
@@ -86,9 +86,14 @@ impl Validator for TimeValidator {
86
86
}
87
87
}
88
88
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
+ } ,
92
97
None => Ok ( None ) ,
93
98
}
94
99
}
0 commit comments