about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-05-03 00:04:59 -0400
committerCorey Farwell <coreyf@rwell.org>2017-05-03 00:04:59 -0400
commita3e8f3622f62022d98c2df1f096f4ef88efb6386 (patch)
tree2f949a5924bf0a03bcb2689a6547ed460b134397 /src/libstd
parentbdd8e7ffe6cb1cdf100b9ca071e826f153371245 (diff)
downloadrust-a3e8f3622f62022d98c2df1f096f4ef88efb6386.tar.gz
rust-a3e8f3622f62022d98c2df1f096f4ef88efb6386.zip
Add doc example for how to determine total number of secs in Duration.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/time/duration.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs
index 4f8f9c36ec7..55766ba3fed 100644
--- a/src/libstd/time/duration.rs
+++ b/src/libstd/time/duration.rs
@@ -128,6 +128,21 @@ impl Duration {
     /// let duration = Duration::new(5, 730023852);
     /// assert_eq!(duration.as_secs(), 5);
     /// ```
+    ///
+    /// To determine the total number of seconds represented by the `Duration`,
+    /// use `as_secs` in combination with [`subsec_nanos`]:
+    ///
+    /// ```
+    /// use std::time::Duration;
+    ///
+    /// let duration = Duration::new(5, 730023852);
+    ///
+    /// assert_eq!(5.730023852,
+    ///            duration.as_secs() as f64
+    ///            + duration.subsec_nanos() as f64 * 1e-9);
+    /// ```
+    ///
+    /// [`subsec_nanos`]: #method.subsec_nanos
     #[stable(feature = "duration", since = "1.3.0")]
     #[inline]
     pub fn as_secs(&self) -> u64 { self.secs }