@@ -240,14 +240,11 @@ pub fn parse_datetime_at_date<S: AsRef<str> + Clone>(
240
240
// reference date could be parsed, then try to parse the entire
241
241
// string as a time delta. If no time delta could be parsed,
242
242
// return an error.
243
- let ( ref_date, n) = match parse_reference_date ( date, s. as_ref ( ) ) {
244
- Some ( ( ref_date, n) ) => ( ref_date, n) ,
245
- None => {
246
- let tz = TimeZone :: from_offset ( date. offset ( ) ) ;
247
- match date. naive_local ( ) . and_local_timezone ( tz) {
248
- MappedLocalTime :: Single ( ref_date) => ( ref_date, 0 ) ,
249
- _ => return Err ( ParseDateTimeError :: InvalidInput ) ,
250
- }
243
+ let ( ref_date, n) = if let Some ( ( ref_date, n) ) = parse_reference_date ( date, s. as_ref ( ) ) { ( ref_date, n) } else {
244
+ let tz = TimeZone :: from_offset ( date. offset ( ) ) ;
245
+ match date. naive_local ( ) . and_local_timezone ( tz) {
246
+ MappedLocalTime :: Single ( ref_date) => ( ref_date, 0 ) ,
247
+ _ => return Err ( ParseDateTimeError :: InvalidInput ) ,
251
248
}
252
249
} ;
253
250
parse_relative_time_at_date ( ref_date, & s. as_ref ( ) [ n..] )
@@ -619,12 +616,12 @@ mod tests {
619
616
for offset in offsets {
620
617
// positive offset
621
618
let time = Utc . timestamp_opt ( offset, 0 ) . unwrap ( ) ;
622
- let dt = parse_datetime ( format ! ( "@{}" , offset ) ) ;
619
+ let dt = parse_datetime ( format ! ( "@{offset}" ) ) ;
623
620
assert_eq ! ( dt. unwrap( ) , time) ;
624
621
625
622
// negative offset
626
623
let time = Utc . timestamp_opt ( -offset, 0 ) . unwrap ( ) ;
627
- let dt = parse_datetime ( format ! ( "@-{}" , offset ) ) ;
624
+ let dt = parse_datetime ( format ! ( "@-{offset}" ) ) ;
628
625
assert_eq ! ( dt. unwrap( ) , time) ;
629
626
}
630
627
}
@@ -642,7 +639,7 @@ mod tests {
642
639
let parsed_time = parse_datetime_at_date ( test_date, "9:04:30 PM +0530" )
643
640
. unwrap ( )
644
641
. timestamp ( ) ;
645
- assert_eq ! ( parsed_time, 1709480070 )
642
+ assert_eq ! ( parsed_time, 1709480070 ) ;
646
643
}
647
644
}
648
645
/// Used to test example code presented in the README.
@@ -862,10 +859,7 @@ mod tests {
862
859
let now = Local :: now ( ) ;
863
860
let midnight = NaiveTime :: from_hms_opt ( 0 , 0 , 0 ) . unwrap ( ) ;
864
861
let today = now. weekday ( ) ;
865
- let midnight_today = match now. with_time ( midnight) {
866
- MappedLocalTime :: Single ( t) => t,
867
- _ => panic ! ( ) ,
868
- } ;
862
+ let midnight_today = if let MappedLocalTime :: Single ( t) = now. with_time ( midnight) { t } else { panic ! ( ) } ;
869
863
870
864
for ( s, day) in [
871
865
( "sunday" , Weekday :: Sun ) ,
@@ -877,7 +871,7 @@ mod tests {
877
871
( "saturday" , Weekday :: Sat ) ,
878
872
] {
879
873
let actual = crate :: parse_datetime ( s) . unwrap ( ) ;
880
- let delta = Days :: new ( day. days_since ( today) as u64 ) ;
874
+ let delta = Days :: new ( u64 :: from ( day. days_since ( today) ) ) ;
881
875
let expected = midnight_today. checked_add_days ( delta) . unwrap ( ) ;
882
876
assert_eq ! ( actual, expected) ;
883
877
}
0 commit comments