@@ -161,7 +161,11 @@ where
161
161
where
162
162
S : Serializer ,
163
163
{
164
- let mut secs = source. sign . apply ( source. duration . as_secs ( ) as i64 ) ;
164
+ let mut secs = source
165
+ . sign
166
+ . apply ( i64:: try_from ( source. duration . as_secs ( ) ) . map_err ( |_| {
167
+ SerError :: custom ( "The Duration of Timestamp is outside the supported range." )
168
+ } ) ?) ;
165
169
166
170
// Properly round the value
167
171
if source. duration . subsec_millis ( ) >= 500 {
@@ -183,6 +187,8 @@ where
183
187
where
184
188
S : Serializer ,
185
189
{
190
+ // as conversions are necessary for floats
191
+ #[ allow( clippy:: as_conversions) ]
186
192
let mut secs = source. sign . apply ( source. duration . as_secs ( ) as f64 ) ;
187
193
188
194
// Properly round the value
@@ -206,7 +212,11 @@ where
206
212
where
207
213
S : Serializer ,
208
214
{
209
- let mut secs = source. sign . apply ( source. duration . as_secs ( ) as i64 ) ;
215
+ let mut secs = source
216
+ . sign
217
+ . apply ( i64:: try_from ( source. duration . as_secs ( ) ) . map_err ( |_| {
218
+ SerError :: custom ( "The Duration of Timestamp is outside the supported range." )
219
+ } ) ?) ;
210
220
211
221
// Properly round the value
212
222
if source. duration . subsec_millis ( ) >= 500 {
@@ -509,7 +519,16 @@ fn parse_float_into_time_parts(mut value: &str) -> Result<(Sign, u64, u32), Pars
509
519
let seconds = parts. next ( ) . expect ( "Float contains exactly one part" ) ;
510
520
if let Ok ( seconds) = seconds. parse ( ) {
511
521
let subseconds = parts. next ( ) . expect ( "Float contains exactly one part" ) ;
512
- let subseclen = subseconds. chars ( ) . count ( ) as u32 ;
522
+ let subseclen = u32:: try_from ( subseconds. chars ( ) . count ( ) ) . map_err ( |_| {
523
+ #[ cfg( feature = "alloc" ) ]
524
+ return ParseFloatError :: Custom ( alloc:: format!(
525
+ "Duration and Timestamps with no more than 9 digits precision, but '{value}' has more"
526
+ ) ) ;
527
+ #[ cfg( not( feature = "alloc" ) ) ]
528
+ return ParseFloatError :: Custom (
529
+ "Duration and Timestamps with no more than 9 digits precision" ,
530
+ ) ;
531
+ } ) ?;
513
532
if subseclen > 9 {
514
533
#[ cfg( feature = "alloc" ) ]
515
534
return Err ( ParseFloatError :: Custom ( alloc:: format!(
0 commit comments