Skip to content

Commit c8734cc

Browse files
committed
Merge pull request #3 from alexcrichton/time
Minor typos and tweaks
2 parents 7c1cb23 + 353b17f commit c8734cc

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

text/0000-time-improvements.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Summary
77

88
This RFC proposes several new types and associated APIs for working with times in Rust.
9-
The primary new types are `Instance`, for working with time that is guaranteed to be
9+
The primary new types are `Instant`, for working with time that is guaranteed to be
1010
monotonic, and `SystemTime`, for working with times across processes on a single system
1111
(usually internally represented as a number of seconds since an epoch).
1212

@@ -121,7 +121,7 @@ directly address time zones.
121121

122122
## Types
123123

124-
```rs
124+
```rust
125125
pub struct Instant {
126126
secs: u64,
127127
nanos: u32
@@ -167,8 +167,11 @@ use for negative values. Rather than require each API that takes a `Duration`
167167
to produce an `Err` (or `panic!`) when receiving a negative value, this design
168168
optimizes for the broadly useful positive `Duration`.
169169

170-
```rs
170+
```rust
171171
impl Instant {
172+
/// Returns an instant corresponding to "now".
173+
pub fn now() -> Instant;
174+
172175
/// Panics if `earlier` is later than &self.
173176
/// Because Instant is monotonic, the only time that `earlier` should be
174177
/// a later time is a bug in your code.
@@ -180,7 +183,7 @@ impl Instant {
180183
}
181184

182185
impl Add<Duration> for Instant {
183-
type Output = SystemTime;
186+
type Output = Instant;
184187
}
185188

186189
impl Sub<Duration> for Instant {
@@ -202,7 +205,7 @@ The "standard" terminology comes from [JodaTime][joda-time-standard].
202205

203206
[joda-time-standard]: http://joda-time.sourceforge.net/apidocs/org/joda/time/Duration.html#standardDays(long)
204207

205-
```rs
208+
```rust
206209
impl Duration {
207210
/// a standard minute is 60 seconds
208211
/// panics if the number of minutes is larger than u64 seconds
@@ -241,8 +244,11 @@ This design attempts to help the programmer catch the most egregious of these
241244
kinds of mistakes (unexpected travel **back in time**) before the mistake
242245
propagates.
243246

244-
```rs
247+
```rust
245248
impl SystemTime {
249+
/// Returns the system time corresponding to "now".
250+
pub fn now() -> SystemTime;
251+
246252
/// Returns an `Err` if `earlier` is later
247253
pub fn duration_from_earlier(&self, earlier: SystemTime) -> Result<Duration, SystemTimeError>;
248254

@@ -258,13 +264,27 @@ impl Sub<Duration> for SystemTime {
258264
type Output = SystemTime;
259265
}
260266

267+
// An anchor which can be used to generate new SystemTime instances from a known
268+
// Duration or convert a SystemTime to a Duration which can later then be used
269+
// again to recreate the SystemTime.
270+
//
271+
// Defined to be "1970-01-01 00:00:00 UTC" on all systems.
272+
const UNIX_EPOCH: SystemTime = ...;
273+
261274
// Note that none of these operations actually imply that the underlying system
262275
// operation that produced these SystemTimes happened at the same time
263276
// (for Eq) or before/after (for Ord) than the other system operation.
264277
impl PartialEq for SystemTime;
265278
impl Eq for SystemTime;
266279
impl PartialOrd for SystemTime;
267280
impl Ord for SystemTime;
281+
282+
impl SystemTimeError {
283+
/// A SystemTimeError originates from attempting to subtract two SystemTime
284+
/// instances, a and b. If a < b then an error is returned, and the duration
285+
/// returned represents (b - a).
286+
pub fn duration(&self) -> Duration;
287+
}
268288
```
269289

270290
The main difference from the design of `Instant` is that it is impossible to
@@ -326,7 +346,5 @@ use `duration_from_earlier` reliably to get a positive `Duration`.
326346

327347
# Unresolved Questions
328348

329-
What should `SystemTimeError` look like?
330-
331349
This RFC leaves types related to human representations of dates and times
332-
to a future proposal.
350+
to a future proposal.

0 commit comments

Comments
 (0)