Skip to content

Commit 1026b7c

Browse files
committed
refactor
1 parent 79d82d4 commit 1026b7c

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

git-date/src/parse.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,13 @@ mod relative {
103103
}
104104

105105
pub(crate) fn parse(input: &str, now: Option<SystemTime>) -> Option<Result<OffsetDateTime, Error>> {
106-
let offset = parse_inner(input).map(|offset| {
107-
let secs = offset.whole_seconds().try_into().expect("positive value");
108-
return std::time::Duration::from_secs(secs);
109-
})?;
110-
now.ok_or(Error::MissingCurrentTime).map(|now| {
111-
now.checked_sub(offset)
112-
.expect("BUG: values can't be large enough to cause underflow")
113-
.into()
106+
parse_inner(input).map(|offset| {
107+
let offset = std::time::Duration::from_secs(offset.whole_seconds().try_into().expect("positive value"));
108+
now.ok_or(Error::MissingCurrentTime).map(|now| {
109+
now.checked_sub(offset)
110+
.expect("BUG: values can't be large enough to cause underflow")
111+
.into()
112+
})
114113
})
115114
}
116115

@@ -125,7 +124,7 @@ mod relative {
125124
// TODO months & years?
126125
_ => return None,
127126
};
128-
Some(Duration::seconds(seconds.checked_mul(multiplier)?))
127+
seconds.checked_mul(multiplier).map(Duration::seconds)
129128
}
130129

131130
#[cfg(test)]
Binary file not shown.

git-date/tests/time/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ mod relative {
9999
use time::{Duration, OffsetDateTime};
100100

101101
#[test]
102-
fn large_offsets_can_panic() {
102+
fn large_offsets() {
103103
git_date::parse("999999999999999 weeks ago", Some(std::time::UNIX_EPOCH)).ok();
104104
}
105105

0 commit comments

Comments
 (0)