Skip to content

Commit

Permalink
Rollup merge of #108370 - fbq:time-doc-fix, r=thomcc
Browse files Browse the repository at this point in the history
std: time: Avoid to use "was created" in elapsed() description

".. since this instant was created" is inaccurate and misleading, consider the following case:
```rust
	let i1 = Instant::now(); // i1 is created at T1
	let i2 = i1 + Duration::from_nanos(0); // i2 is "created" at T2
	i2.elapsed(); // at T3
```
Per the current description, `elapsed()` at T3 should return T3 - T2?

To avoid the inaccuracy, removes the "was created" in the description of {Instant,SystemTime}::elapsed().
And since these types represent times, it's OK to use prepostions with them, e.g. "since this instant".
  • Loading branch information
Dylan-DPC authored Feb 24, 2023
2 parents 251293e + b54a5fd commit f94c3c9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions library/std/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ impl Instant {
self.checked_duration_since(earlier).unwrap_or_default()
}

/// Returns the amount of time elapsed since this instant was created.
/// Returns the amount of time elapsed since this instant.
///
/// # Panics
///
Expand Down Expand Up @@ -525,8 +525,8 @@ impl SystemTime {
self.0.sub_time(&earlier.0).map_err(SystemTimeError)
}

/// Returns the difference between the clock time when this
/// system time was created, and the current clock time.
/// Returns the difference from this system time to the
/// current clock time.
///
/// This function may fail as the underlying system clock is susceptible to
/// drift and updates (e.g., the system clock could go backwards), so this
Expand Down

0 comments on commit f94c3c9

Please sign in to comment.