Skip to content

Commit bfc8f72

Browse files
committed
fix clippy pedantic
1 parent 93e1c9b commit bfc8f72

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

src/lib.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,11 @@ pub fn parse_datetime_at_date<S: AsRef<str> + Clone>(
240240
// reference date could be parsed, then try to parse the entire
241241
// string as a time delta. If no time delta could be parsed,
242242
// 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),
251248
}
252249
};
253250
parse_relative_time_at_date(ref_date, &s.as_ref()[n..])
@@ -619,12 +616,12 @@ mod tests {
619616
for offset in offsets {
620617
// positive offset
621618
let time = Utc.timestamp_opt(offset, 0).unwrap();
622-
let dt = parse_datetime(format!("@{}", offset));
619+
let dt = parse_datetime(format!("@{offset}"));
623620
assert_eq!(dt.unwrap(), time);
624621

625622
// negative offset
626623
let time = Utc.timestamp_opt(-offset, 0).unwrap();
627-
let dt = parse_datetime(format!("@-{}", offset));
624+
let dt = parse_datetime(format!("@-{offset}"));
628625
assert_eq!(dt.unwrap(), time);
629626
}
630627
}
@@ -642,7 +639,7 @@ mod tests {
642639
let parsed_time = parse_datetime_at_date(test_date, "9:04:30 PM +0530")
643640
.unwrap()
644641
.timestamp();
645-
assert_eq!(parsed_time, 1709480070)
642+
assert_eq!(parsed_time, 1709480070);
646643
}
647644
}
648645
/// Used to test example code presented in the README.
@@ -862,10 +859,7 @@ mod tests {
862859
let now = Local::now();
863860
let midnight = NaiveTime::from_hms_opt(0, 0, 0).unwrap();
864861
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!() };
869863

870864
for (s, day) in [
871865
("sunday", Weekday::Sun),
@@ -877,7 +871,7 @@ mod tests {
877871
("saturday", Weekday::Sat),
878872
] {
879873
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)));
881875
let expected = midnight_today.checked_add_days(delta).unwrap();
882876
assert_eq!(actual, expected);
883877
}

src/parse_time_only_str.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ mod tests {
140140
let parsed_time = parse_time_only(get_test_date(), "21:04")
141141
.unwrap()
142142
.timestamp();
143-
assert_eq!(parsed_time, 1709499840)
143+
assert_eq!(parsed_time, 1709499840);
144144
}
145145

146146
#[test]
@@ -187,7 +187,7 @@ mod tests {
187187
let parsed_time = parse_time_only(get_test_date(), "21:04:30")
188188
.unwrap()
189189
.timestamp();
190-
assert_eq!(parsed_time, 1709499870)
190+
assert_eq!(parsed_time, 1709499870);
191191
}
192192

193193
#[test]
@@ -196,7 +196,7 @@ mod tests {
196196
let parsed_time = parse_time_only(get_test_date(), "21:04:30 +0530")
197197
.unwrap()
198198
.timestamp();
199-
assert_eq!(parsed_time, 1709480070)
199+
assert_eq!(parsed_time, 1709480070);
200200
}
201201

202202
#[test]
@@ -205,6 +205,6 @@ mod tests {
205205
let parsed_time = parse_time_only(get_test_date(), "9:04:00 PM")
206206
.unwrap()
207207
.timestamp();
208-
assert_eq!(parsed_time, 1709499840)
208+
assert_eq!(parsed_time, 1709499840);
209209
}
210210
}

src/parse_weekday.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ mod tests {
6464

6565
for (name, weekday) in days {
6666
assert_eq!(parse_weekday(name), Some(weekday));
67-
assert_eq!(parse_weekday(&format!(" {}", name)), Some(weekday));
68-
assert_eq!(parse_weekday(&format!(" {} ", name)), Some(weekday));
69-
assert_eq!(parse_weekday(&format!("{} ", name)), Some(weekday));
67+
assert_eq!(parse_weekday(&format!(" {name}")), Some(weekday));
68+
assert_eq!(parse_weekday(&format!(" {name} ")), Some(weekday));
69+
assert_eq!(parse_weekday(&format!("{name} ")), Some(weekday));
7070

7171
let (left, right) = name.split_at(1);
7272
let (test_str1, test_str2) = (

0 commit comments

Comments
 (0)