Skip to content

Commit

Permalink
Auto merge of #49501 - sfackler:unix-epoch-assoc-const, r=alexcrichton
Browse files Browse the repository at this point in the history
Make UNIX_EPOCH an associated constant of SystemTime

It's not very discoverable as a separate const in the module.

r? @alexcrichton
  • Loading branch information
bors committed Mar 31, 2018
2 parents 70248b1 + df2e238 commit e38eca6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/libstd/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,29 @@ impl fmt::Debug for Instant {
}

impl SystemTime {
/// An anchor in time which can be used to create new `SystemTime` instances or
/// learn about where in time a `SystemTime` lies.
///
/// This constant is defined to be "1970-01-01 00:00:00 UTC" on all systems with
/// respect to the system clock. Using `duration_since` on an existing
/// `SystemTime` instance can tell how far away from this point in time a
/// measurement lies, and using `UNIX_EPOCH + duration` can be used to create a
/// `SystemTime` instance to represent another fixed point in time.
///
/// # Examples
///
/// ```no_run
/// #![feature(assoc_unix_epoch)]
/// use std::time::SystemTime;
///
/// match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
/// Ok(n) => println!("1970-01-01 00:00:00 UTC was {} seconds ago!", n.as_secs()),
/// Err(_) => panic!("SystemTime before UNIX EPOCH!"),
/// }
/// ```
#[unstable(feature = "assoc_unix_epoch", issue = "49502")]
pub const UNIX_EPOCH: SystemTime = UNIX_EPOCH;

/// Returns the system time corresponding to "now".
///
/// # Examples
Expand Down

0 comments on commit e38eca6

Please sign in to comment.