diff --git a/src/lib.rs b/src/lib.rs index 0daab92..8650c86 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -169,7 +169,7 @@ impl std::ops::Sub for Instant { impl std::ops::Sub for Instant { type Output = Instant; fn sub(self, rhs: Duration) -> Self::Output { - self.checked_add(rhs) + self.checked_sub(rhs) .expect("overflow when substracting duration from instant") } } @@ -268,6 +268,12 @@ mod tests { Instant(Duration::from_millis(41)) ); + // now - 1 = diff - 1 + assert_eq!( + Instant::now() - Duration::from_millis(1), + Instant(Duration::from_millis(41)) + ); + // now - diff + 1 = none assert!(Instant::now() .checked_sub(Duration::from_millis(43))