about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-08-11 03:47:16 +0000
committerbors <bors@rust-lang.org>2015-08-11 03:47:16 +0000
commit50141d7e1e5b1b539d45240dff709fa68e7472c2 (patch)
treeafd3b867660ee71b379e1d6dbcc5d8bab2170397 /src/libstd/sys
parent8b3705528ab6a7511928d46c654cc0040272f48d (diff)
parentb51e0090696c82c6156bbfcd0e67ac68df67379b (diff)
downloadrust-50141d7e1e5b1b539d45240dff709fa68e7472c2.tar.gz
rust-50141d7e1e5b1b539d45240dff709fa68e7472c2.zip
Auto merge of #26818 - sfackler:duration-stabilization, r=aturon
This commit stabilizes the `std::time` module and the `Duration` type.
`Duration::span` remains unstable, and the `Display` implementation for
`Duration` has been removed as it is still being reworked and all trait
implementations for stable types are de facto stable.

This is a [breaking-change] to those using `Duration`'s `Display`
implementation.

I'm opening this PR as a platform for discussion - there may be some method renaming to do as part of the stabilization process.
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/unix/condvar.rs4
-rw-r--r--src/libstd/sys/unix/net.rs8
-rw-r--r--src/libstd/sys/unix/thread.rs4
-rw-r--r--src/libstd/sys/windows/mod.rs6
4 files changed, 11 insertions, 11 deletions
diff --git a/src/libstd/sys/unix/condvar.rs b/src/libstd/sys/unix/condvar.rs
index 9dd8df7524d..5d18c1d6280 100644
--- a/src/libstd/sys/unix/condvar.rs
+++ b/src/libstd/sys/unix/condvar.rs
@@ -61,11 +61,11 @@ impl Condvar {
         let r = ffi::gettimeofday(&mut sys_now, ptr::null_mut());
         debug_assert_eq!(r, 0);
 
-        let nsec = dur.extra_nanos() as libc::c_long +
+        let nsec = dur.subsec_nanos() as libc::c_long +
                    (sys_now.tv_usec * 1000) as libc::c_long;
         let extra = (nsec / 1_000_000_000) as libc::time_t;
         let nsec = nsec % 1_000_000_000;
-        let seconds = dur.secs() as libc::time_t;
+        let seconds = dur.as_secs() as libc::time_t;
 
         let timeout = sys_now.tv_sec.checked_add(extra).and_then(|s| {
             s.checked_add(seconds)
diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs
index 37eb7fd2ac8..e65f64f2029 100644
--- a/src/libstd/sys/unix/net.rs
+++ b/src/libstd/sys/unix/net.rs
@@ -79,19 +79,19 @@ impl Socket {
     pub fn set_timeout(&self, dur: Option<Duration>, kind: libc::c_int) -> io::Result<()> {
         let timeout = match dur {
             Some(dur) => {
-                if dur.secs() == 0 && dur.extra_nanos() == 0 {
+                if dur.as_secs() == 0 && dur.subsec_nanos() == 0 {
                     return Err(io::Error::new(io::ErrorKind::InvalidInput,
                                               "cannot set a 0 duration timeout"));
                 }
 
-                let secs = if dur.secs() > libc::time_t::max_value() as u64 {
+                let secs = if dur.as_secs() > libc::time_t::max_value() as u64 {
                     libc::time_t::max_value()
                 } else {
-                    dur.secs() as libc::time_t
+                    dur.as_secs() as libc::time_t
                 };
                 let mut timeout = libc::timeval {
                     tv_sec: secs,
-                    tv_usec: (dur.extra_nanos() / 1000) as libc::suseconds_t,
+                    tv_usec: (dur.subsec_nanos() / 1000) as libc::suseconds_t,
                 };
                 if timeout.tv_sec == 0 && timeout.tv_usec == 0 {
                     timeout.tv_usec = 1;
diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs
index ea1bfbd9b7d..fc0bb81f9a8 100644
--- a/src/libstd/sys/unix/thread.rs
+++ b/src/libstd/sys/unix/thread.rs
@@ -128,8 +128,8 @@ impl Thread {
 
     pub fn sleep(dur: Duration) {
         let mut ts = libc::timespec {
-            tv_sec: dur.secs() as libc::time_t,
-            tv_nsec: dur.extra_nanos() as libc::c_long,
+            tv_sec: dur.as_secs() as libc::time_t,
+            tv_nsec: dur.subsec_nanos() as libc::c_long,
         };
 
         // If we're awoken with a signal then the return value will be -1 and
diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs
index b6d080109df..b38945d8916 100644
--- a/src/libstd/sys/windows/mod.rs
+++ b/src/libstd/sys/windows/mod.rs
@@ -162,10 +162,10 @@ fn dur2timeout(dur: Duration) -> libc::DWORD {
     // * Nanosecond precision is rounded up
     // * Greater than u32::MAX milliseconds (50 days) is rounded up to INFINITE
     //   (never time out).
-    dur.secs().checked_mul(1000).and_then(|ms| {
-        ms.checked_add((dur.extra_nanos() as u64) / 1_000_000)
+    dur.as_secs().checked_mul(1000).and_then(|ms| {
+        ms.checked_add((dur.subsec_nanos() as u64) / 1_000_000)
     }).and_then(|ms| {
-        ms.checked_add(if dur.extra_nanos() % 1_000_000 > 0 {1} else {0})
+        ms.checked_add(if dur.subsec_nanos() % 1_000_000 > 0 {1} else {0})
     }).map(|ms| {
         if ms > <libc::DWORD>::max_value() as u64 {
             libc::INFINITE