Move util::time::duration_from_seconds to profile::time

This commit is contained in:
Anthony Ramine 2016-06-29 17:44:17 +02:00
parent f8f00fac5b
commit 5a576e873e
4 changed files with 16 additions and 24 deletions

View file

@ -48,7 +48,6 @@ pub mod str;
pub mod thread;
pub mod thread_state;
pub mod tid;
#[cfg(feature = "servo")] pub mod time;
pub mod vec;
#[allow(unsafe_code)] pub mod workqueue;

View file

@ -1,20 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use std::time::Duration;
use std::{u32, u64};
pub const NANOS_PER_SEC: u32 = 1_000_000_000;
pub fn duration_from_seconds(secs: f64) -> Duration {
// Get number of seconds and check that it fits in a u64.
let whole_secs = secs.trunc();
assert!(whole_secs >= 0.0 && whole_secs <= u64::MAX as f64);
// Get number of nanoseconds. This should always fit in a u32, but check anyway.
let nanos = (secs.fract() * (NANOS_PER_SEC as f64)).trunc();
assert!(nanos >= 0.0 && nanos <= u32::MAX as f64);
Duration::new(whole_secs as u64, nanos as u32)
}