Skip to content

Commit

Permalink
Rename checked_add_duration to checked_add and make it take the durat…
Browse files Browse the repository at this point in the history
…ion by value
  • Loading branch information
sgeisler committed Nov 15, 2018
1 parent 166f7d9 commit 8231831
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/libstd/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,9 @@ impl SystemTime {
/// Returns `Some(t)` where `t` is the time `self + duration` if `t` can be represented as
/// `SystemTime` (which means it's inside the bounds of the underlying data structure), `None`
/// otherwise.
#[stable(feature = "time_checked_add", since = "1.32.0")]
pub fn checked_add_duration(&self, duration: &Duration) -> Option<SystemTime> {
self.0.checked_add_duration(duration).map(|t| SystemTime(t))
#[unstable(feature = "time_checked_add", issue = "55940")]
pub fn checked_add(&self, duration: Duration) -> Option<SystemTime> {
self.0.checked_add_duration(&duration).map(|t| SystemTime(t))
}
}

Expand Down Expand Up @@ -571,13 +571,13 @@ mod tests {
let max_duration = Duration::from_secs(u64::max_value());
// in case `SystemTime` can store `>= UNIX_EPOCH + max_duration`.
for _ in 0..2 {
maybe_t = maybe_t.and_then(|t| t.checked_add_duration(&max_duration));
maybe_t = maybe_t.and_then(|t| t.checked_add(max_duration));
}
assert_eq!(maybe_t, None);

// checked_add_duration calculates the right time and will work for another year
let year = Duration::from_secs(60 * 60 * 24 * 365);
assert_eq!(a + year, a.checked_add_duration(&year).unwrap());
assert_eq!(a + year, a.checked_add(year).unwrap());
}

#[test]
Expand Down

0 comments on commit 8231831

Please sign in to comment.