Skip to content

Commit

Permalink
Make duration_since use checked_duration_since
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Mar 22, 2019
1 parent 37cfeb2 commit d56b1fd
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/libstd/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl Instant {
/// ```
#[stable(feature = "time2", since = "1.8.0")]
pub fn duration_since(&self, earlier: Instant) -> Duration {
self.0.sub_instant(&earlier.0)
self.0.checked_sub_instant(&earlier.0).expect("supplied instant is later than self")
}

/// Returns the amount of time elapsed from another instant to this one,
Expand All @@ -233,11 +233,7 @@ impl Instant {
/// ```
#[unstable(feature = "checked_duration_since", issue = "58402")]
pub fn checked_duration_since(&self, earlier: Instant) -> Option<Duration> {
if self >= &earlier {
Some(self.0.sub_instant(&earlier.0))
} else {
None
}
self.0.checked_sub_instant(&earlier.0)
}

/// Returns the amount of time elapsed from another instant to this one,
Expand Down

0 comments on commit d56b1fd

Please sign in to comment.