Skip to content

Commit 1eca229

Browse files
committed
Draft.
1 parent 0a20909 commit 1eca229

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

git-date/src/parse.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ mod relative {
2626
use time::{Duration, OffsetDateTime};
2727

2828
pub(crate) fn parse(input: &str) -> Option<OffsetDateTime> {
29-
let split: Vec<&str> = input.split_whitespace().collect();
30-
if split.len() != 3 || *split.last().expect("slice has length 3") != "ago" {
29+
let mut split = input.split_whitespace();
30+
let multiplier = i64::from_str(split.next()?).ok()?;
31+
let period = period_to_seconds(split.next()?)?;
32+
if split.next()? != "ago" {
3133
return None;
3234
}
33-
let multiplier = i64::from_str(split[0]).ok()?;
34-
let period = period_to_seconds(split[1])?;
3535
Some(OffsetDateTime::now_utc().checked_sub(Duration::seconds(multiplier * period))?)
3636
}
3737

0 commit comments

Comments
 (0)