File tree 2 files changed +29
-11
lines changed
2 files changed +29
-11
lines changed Original file line number Diff line number Diff line change @@ -303,7 +303,7 @@ fn with_timezone_restore(
303
303
offset : time:: Offset ,
304
304
at : DateTime < FixedOffset > ,
305
305
) -> Option < DateTime < FixedOffset > > {
306
- let offset: FixedOffset = chrono:: FixedOffset :: from ( offset) ;
306
+ let offset: FixedOffset = chrono:: FixedOffset :: try_from ( offset) . ok ( ) ? ;
307
307
let copy = at;
308
308
let x = at
309
309
. with_timezone ( & offset)
@@ -360,7 +360,9 @@ fn at_date_inner(date: Vec<Item>, mut d: DateTime<FixedOffset>) -> Option<DateTi
360
360
} ,
361
361
..
362
362
} ) => {
363
- let offset = offset. map ( chrono:: FixedOffset :: from) . unwrap_or ( * d. offset ( ) ) ;
363
+ let offset = offset
364
+ . and_then ( |o| chrono:: FixedOffset :: try_from ( o) . ok ( ) )
365
+ . unwrap_or ( * d. offset ( ) ) ;
364
366
365
367
d = new_date (
366
368
year. map ( |x| x as i32 ) . unwrap_or ( d. year ( ) ) ,
@@ -379,7 +381,10 @@ fn at_date_inner(date: Vec<Item>, mut d: DateTime<FixedOffset>) -> Option<DateTi
379
381
second,
380
382
offset,
381
383
} ) => {
382
- let offset = offset. map ( chrono:: FixedOffset :: from) . unwrap_or ( * d. offset ( ) ) ;
384
+ let offset = offset
385
+ . and_then ( |o| chrono:: FixedOffset :: try_from ( o) . ok ( ) )
386
+ . unwrap_or ( * d. offset ( ) ) ;
387
+
383
388
d = new_date (
384
389
d. year ( ) ,
385
390
d. month ( ) ,
Original file line number Diff line number Diff line change @@ -50,6 +50,8 @@ use winnow::{
50
50
ModalResult , Parser ,
51
51
} ;
52
52
53
+ use crate :: ParseDateTimeError ;
54
+
53
55
use super :: { dec_uint, relative, s} ;
54
56
55
57
#[ derive( PartialEq , Debug , Clone , Default ) ]
@@ -95,22 +97,33 @@ impl Offset {
95
97
}
96
98
}
97
99
98
- impl From < Offset > for chrono:: FixedOffset {
99
- fn from (
100
+ impl TryFrom < Offset > for chrono:: FixedOffset {
101
+ type Error = ParseDateTimeError ;
102
+
103
+ fn try_from (
100
104
Offset {
101
105
negative,
102
106
hours,
103
107
minutes,
104
108
} : Offset ,
105
- ) -> Self {
109
+ ) -> Result < Self , Self :: Error > {
106
110
let secs = hours * 3600 + minutes * 60 ;
107
111
108
- if negative {
109
- FixedOffset :: west_opt ( secs. try_into ( ) . expect ( "secs overflow" ) )
110
- . expect ( "timezone overflow" )
112
+ let offset = if negative {
113
+ FixedOffset :: west_opt (
114
+ secs. try_into ( )
115
+ . map_err ( |_| ParseDateTimeError :: InvalidInput ) ?,
116
+ )
117
+ . ok_or ( ParseDateTimeError :: InvalidInput ) ?
111
118
} else {
112
- FixedOffset :: east_opt ( secs. try_into ( ) . unwrap ( ) ) . unwrap ( )
113
- }
119
+ FixedOffset :: east_opt (
120
+ secs. try_into ( )
121
+ . map_err ( |_| ParseDateTimeError :: InvalidInput ) ?,
122
+ )
123
+ . ok_or ( ParseDateTimeError :: InvalidInput ) ?
124
+ } ;
125
+
126
+ Ok ( offset)
114
127
}
115
128
}
116
129
You can’t perform that action at this time.
0 commit comments