about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-03-31 15:33:28 +0000
committerbors <bors@rust-lang.org>2018-03-31 15:33:28 +0000
commite38eca6caca2bcb7da36d3075b390625b717fbab (patch)
tree3ac624a3fe89511a142d80ce86ffdbacfb94a0f8 /src/libstd
parent70248b1fcf9bab8bdc9d259137ba257fed7134ac (diff)
parentdf2e238d1aae617f75424a2928d35cc39fae0fa0 (diff)
downloadrust-e38eca6caca2bcb7da36d3075b390625b717fbab.tar.gz
rust-e38eca6caca2bcb7da36d3075b390625b717fbab.zip
Auto merge of #49501 - sfackler:unix-epoch-assoc-const, r=alexcrichton
Make UNIX_EPOCH an associated constant of SystemTime

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

r? @alexcrichton
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/time.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/libstd/time.rs b/src/libstd/time.rs
index 7256ac43e27..1215302757c 100644
--- a/src/libstd/time.rs
+++ b/src/libstd/time.rs
@@ -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