Bug 1716518 - Upgrade time to v0.1.43.

Latest version is v0.1.44 but it adds new dependencies.

Differential Revision: https://phabricator.services.mozilla.com/D117868

Depends on D117867
This commit is contained in:
Mike Hommey 2021-06-15 09:25:41 +00:00
Родитель 3db90b3546
Коммит cf05913533
11 изменённых файлов: 134 добавлений и 210 удалений

5
Cargo.lock сгенерированный
Просмотреть файл

@ -5102,12 +5102,11 @@ checksum = "87b4947742c93ece24a0032141d9caa3d853752e694a57e35029dd2bd08673e0"
[[package]]
name = "time"
version = "0.1.40"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b"
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
dependencies = [
"libc",
"redox_syscall",
"winapi",
]

2
third_party/rust/time/.cargo-checksum.json поставляемый
Просмотреть файл

@ -1 +1 @@
{"files":{"Cargo.toml":"3c15858858af40a4cfa78a73cea88ba2e4ff31a59e7c7d2fef17d2282c9aa6e7","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"2c17f942c4a797f6f491c6d40570f904f35047531884ded3244438832b3d6f0a","appveyor.yml":"da991211b72fa6f231af7adb84c9fb72f5a9131d1c0a3d47b8ceffe5a82c8542","benches/precise_time_ns.rs":"06206c16764c6cef71da645ddb1aa7476dff7697e38d0742b3c907be9f00dadf","src/display.rs":"b79a81b4f068e44934ad3398ba0259120cc30cf0855ac5108c4569e320fd7f1d","src/duration.rs":"c227f6809f837996d24145843ba4972650d0fca7e2af7bbb0ebc0dbcec3358d9","src/lib.rs":"a07a09d4955fc92b85eb854e136a2732b94feff1c9be97fcf49accde6e704ee7","src/parse.rs":"717ae5735dfdaaba513f2a54a179e73bb2a48f8d4fb8787740d4662d6ff3389c","src/sys.rs":"14e3f57e7cf63167eda2f2fead3e01e59eb4cf71a5b15ae7563e962a43dbc659"},"package":"d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b"}
{"files":{"Cargo.toml":"ddebccd9128093c3fdf84b4f6a131fe634c85e8fc2059afed9ea30e02fe22c58","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"35b591c7481ec3ae59210fa4f9b7cecb1b16e632bfd6193b032239e74f9bfdb8","src/display.rs":"52d16abaa37b3ab577747c7d9d2ed6ded1b126458e980dc3e1a571fa6e1f9fda","src/duration.rs":"c706d392bdb7f65b23fcc20189a9a77c50b765b9c548e247238424ed6fb56a46","src/lib.rs":"720e380829cda276466bce34d6a29a2f7aec1f750e4b4522b217c57930380545","src/parse.rs":"65bd9142d8c15eb54a8d4db6e2c48bf1adbcc875953141c17e07ba58f356a027","src/sys.rs":"851994516ff29dd9f5749fa19b1db13b7afe484e4bd1d279b420fda7ed8404ab"},"package":"ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"}

21
third_party/rust/time/Cargo.toml поставляемый
Просмотреть файл

@ -3,7 +3,7 @@
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g. crates.io) dependencies
# to registry (e.g., crates.io) dependencies
#
# If you believe there's an error in this file please file an
# issue against the rust-lang/cargo repository. If you're
@ -12,15 +12,17 @@
[package]
name = "time"
version = "0.1.40"
version = "0.1.43"
authors = ["The Rust Project Developers"]
exclude = [".github", "benches"]
description = "Utilities for working with time-related functions in Rust.\n"
homepage = "https://github.com/rust-lang/time"
documentation = "https://doc.rust-lang.org/time"
homepage = "https://github.com/time-rs/time"
documentation = "https://docs.rs/time/~0.1"
readme = "README.md"
license = "MIT/Apache-2.0"
repository = "https://github.com/rust-lang/time"
repository = "https://github.com/time-rs/time"
[dependencies.libc]
version = "0.2.1"
version = "0.2.69"
[dependencies.rustc-serialize]
version = "0.3"
@ -31,13 +33,6 @@ version = "0.4"
[dev-dependencies.winapi]
version = "0.3.0"
features = ["std", "processthreadsapi", "winbase"]
[target."cfg(target_os = \"redox\")".dependencies.redox_syscall]
version = "0.1"
[target."cfg(windows)".dependencies.winapi]
version = "0.3.0"
features = ["std", "minwinbase", "minwindef", "ntdef", "profileapi", "sysinfoapi", "timezoneapi"]
[badges.appveyor]
repository = "alexcrichton/time"
[badges.travis-ci]
repository = "rust-lang-deprecated/time"

15
third_party/rust/time/README.md поставляемый
Просмотреть файл

@ -3,16 +3,17 @@ time
Utilities for working with time-related functions in Rust
[![Build Status](https://travis-ci.org/rust-lang-deprecated/time.svg?branch=master)](https://travis-ci.org/rust-lang-deprecated/time)
[![Build status](https://ci.appveyor.com/api/projects/status/55m7rbaj9a5v3ad7?svg=true)](https://ci.appveyor.com/project/alexcrichton/time)
[![build status](https://github.com/time-rs/time/workflows/Build/badge.svg?branch=v0.1)](https://github.com/time-rs/time/actions?query=branch%3Av0.1)
[![Documentation](https://docs.rs/time/badge.svg?version=0.1)](https://docs.rs/time/~0.1)
![rustc 1.21.0](https://img.shields.io/badge/rustc-1.21.0-blue)
[Documentation](https://doc.rust-lang.org/time)
## time v0.1.x is Deprecated
## Notes
The 0.1.x series of this library is deprecated and in maintenance mode. No new
features will be added. Active development now occurs in the 0.2.x series.
This library is no longer actively maintained, but bugfixes will be added ([details](https://github.com/rust-lang-deprecated/time/issues/136)).
In case you're looking for something a little fresher and more actively maintained have a look at the [`chrono`](https://github.com/lifthrasiir/rust-chrono) crate.
If you need additional functionality that this crate does not provide, check
out the [`chrono`](https://github.com/chronotope/chrono) crate.
## Usage

17
third_party/rust/time/appveyor.yml поставляемый
Просмотреть файл

@ -1,17 +0,0 @@
environment:
matrix:
- TARGET: x86_64-pc-windows-msvc
- TARGET: i686-pc-windows-msvc
- TARGET: i686-pc-windows-gnu
install:
- ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-nightly-${env:TARGET}.exe"
- rust-nightly-%TARGET%.exe /VERYSILENT /NORESTART /DIR="C:\Program Files (x86)\Rust"
- SET PATH=%PATH%;C:\Program Files (x86)\Rust\bin
- SET PATH=%PATH%;C:\MinGW\bin
- rustc -V
- cargo -V
build: false
test_script:
- cargo test --verbose

Просмотреть файл

@ -1,14 +0,0 @@
#![feature(test)]
extern crate test;
extern crate time;
use test::Bencher;
#[bench]
fn bench_precise_time_ns(b: &mut Bencher) {
b.iter(|| {
time::precise_time_ns();
time::precise_time_ns();
});
}

68
third_party/rust/time/src/display.rs поставляемый
Просмотреть файл

@ -11,9 +11,9 @@ impl<'a> fmt::Display for TmFmt<'a> {
if ch == '%' {
// we've already validated that % always precedes
// another char
try!(parse_type(fmt, chars.next().unwrap(), self.tm));
parse_type(fmt, chars.next().unwrap(), self.tm)?;
} else {
try!(fmt.write_char(ch));
fmt.write_char(ch)?;
}
}
@ -148,31 +148,31 @@ fn parse_type(fmt: &mut fmt::Formatter, ch: char, tm: &Tm) -> fmt::Result {
}),
'C' => write!(fmt, "{:02}", (tm.tm_year + 1900) / 100),
'c' => {
try!(parse_type(fmt, 'a', tm));
try!(fmt.write_str(" "));
try!(parse_type(fmt, 'b', tm));
try!(fmt.write_str(" "));
try!(parse_type(fmt, 'e', tm));
try!(fmt.write_str(" "));
try!(parse_type(fmt, 'T', tm));
try!(fmt.write_str(" "));
parse_type(fmt, 'a', tm)?;
fmt.write_str(" ")?;
parse_type(fmt, 'b', tm)?;
fmt.write_str(" ")?;
parse_type(fmt, 'e', tm)?;
fmt.write_str(" ")?;
parse_type(fmt, 'T', tm)?;
fmt.write_str(" ")?;
parse_type(fmt, 'Y', tm)
}
'D' | 'x' => {
try!(parse_type(fmt, 'm', tm));
try!(fmt.write_str("/"));
try!(parse_type(fmt, 'd', tm));
try!(fmt.write_str("/"));
parse_type(fmt, 'm', tm)?;
fmt.write_str("/")?;
parse_type(fmt, 'd', tm)?;
fmt.write_str("/")?;
parse_type(fmt, 'y', tm)
}
'd' => write!(fmt, "{:02}", tm.tm_mday),
'e' => write!(fmt, "{:2}", tm.tm_mday),
'f' => write!(fmt, "{:09}", tm.tm_nsec),
'F' => {
try!(parse_type(fmt, 'Y', tm));
try!(fmt.write_str("-"));
try!(parse_type(fmt, 'm', tm));
try!(fmt.write_str("-"));
parse_type(fmt, 'Y', tm)?;
fmt.write_str("-")?;
parse_type(fmt, 'm', tm)?;
fmt.write_str("-")?;
parse_type(fmt, 'd', tm)
}
'G' => iso_week(fmt, 'G', tm),
@ -198,26 +198,26 @@ fn parse_type(fmt: &mut fmt::Formatter, ch: char, tm: &Tm) -> fmt::Result {
'P' => fmt.write_str(if tm.tm_hour < 12 { "am" } else { "pm" }),
'p' => fmt.write_str(if (tm.tm_hour) < 12 { "AM" } else { "PM" }),
'R' => {
try!(parse_type(fmt, 'H', tm));
try!(fmt.write_str(":"));
parse_type(fmt, 'H', tm)?;
fmt.write_str(":")?;
parse_type(fmt, 'M', tm)
}
'r' => {
try!(parse_type(fmt, 'I', tm));
try!(fmt.write_str(":"));
try!(parse_type(fmt, 'M', tm));
try!(fmt.write_str(":"));
try!(parse_type(fmt, 'S', tm));
try!(fmt.write_str(" "));
parse_type(fmt, 'I', tm)?;
fmt.write_str(":")?;
parse_type(fmt, 'M', tm)?;
fmt.write_str(":")?;
parse_type(fmt, 'S', tm)?;
fmt.write_str(" ")?;
parse_type(fmt, 'p', tm)
}
'S' => write!(fmt, "{:02}", tm.tm_sec),
's' => write!(fmt, "{}", tm.to_timespec().sec),
'T' | 'X' => {
try!(parse_type(fmt, 'H', tm));
try!(fmt.write_str(":"));
try!(parse_type(fmt, 'M', tm));
try!(fmt.write_str(":"));
parse_type(fmt, 'H', tm)?;
fmt.write_str(":")?;
parse_type(fmt, 'M', tm)?;
fmt.write_str(":")?;
parse_type(fmt, 'S', tm)
}
't' => fmt.write_str("\t"),
@ -228,10 +228,10 @@ fn parse_type(fmt: &mut fmt::Formatter, ch: char, tm: &Tm) -> fmt::Result {
}
'V' => iso_week(fmt, 'V', tm),
'v' => {
try!(parse_type(fmt, 'e', tm));
try!(fmt.write_str("-"));
try!(parse_type(fmt, 'b', tm));
try!(fmt.write_str("-"));
parse_type(fmt, 'e', tm)?;
fmt.write_str("-")?;
parse_type(fmt, 'b', tm)?;
fmt.write_str("-")?;
parse_type(fmt, 'Y', tm)
}
'W' => {

23
third_party/rust/time/src/duration.rs поставляемый
Просмотреть файл

@ -41,7 +41,7 @@ macro_rules! try_opt {
/// ISO 8601 time duration with nanosecond precision.
/// This also allows for the negative duration; see individual methods for details.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
pub struct Duration {
secs: i64,
nanos: i32, // Always 0 <= nanos < NANOS_PER_SEC
@ -83,7 +83,7 @@ impl Duration {
/// Panics when the duration is out of bounds.
#[inline]
pub fn hours(hours: i64) -> Duration {
let secs = hours.checked_mul(SECS_PER_HOUR).expect("Duration::hours ouf of bounds");
let secs = hours.checked_mul(SECS_PER_HOUR).expect("Duration::hours out of bounds");
Duration::seconds(secs)
}
@ -285,6 +285,12 @@ impl Duration {
}
Ok(StdDuration::new(self.secs as u64, self.nanos as u32))
}
/// Returns the raw value of duration.
#[cfg(target_env = "sgx")]
pub(crate) fn raw(&self) -> (i64, i32) {
(self.secs, self.nanos)
}
}
impl Neg for Duration {
@ -371,20 +377,20 @@ impl fmt::Display for Duration {
let hasdate = days != 0;
let hastime = (secs != 0 || abs.nanos != 0) || !hasdate;
try!(write!(f, "{}P", sign));
write!(f, "{}P", sign)?;
if hasdate {
try!(write!(f, "{}D", days));
write!(f, "{}D", days)?;
}
if hastime {
if abs.nanos == 0 {
try!(write!(f, "T{}S", secs));
write!(f, "T{}S", secs)?;
} else if abs.nanos % NANOS_PER_MILLI == 0 {
try!(write!(f, "T{}.{:03}S", secs, abs.nanos / NANOS_PER_MILLI));
write!(f, "T{}.{:03}S", secs, abs.nanos / NANOS_PER_MILLI)?;
} else if abs.nanos % NANOS_PER_MICRO == 0 {
try!(write!(f, "T{}.{:06}S", secs, abs.nanos / NANOS_PER_MICRO));
write!(f, "T{}.{:06}S", secs, abs.nanos / NANOS_PER_MICRO)?;
} else {
try!(write!(f, "T{}.{:09}S", secs, abs.nanos));
write!(f, "T{}.{:09}S", secs, abs.nanos)?;
}
}
Ok(())
@ -401,6 +407,7 @@ impl fmt::Display for Duration {
pub struct OutOfRangeError(());
impl fmt::Display for OutOfRangeError {
#[allow(deprecated)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}

18
third_party/rust/time/src/lib.rs поставляемый
Просмотреть файл

@ -33,10 +33,11 @@
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "https://www.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/time/")]
#![allow(unknown_lints)]
#![allow(ellipsis_inclusive_range_patterns)] // `..=` requires Rust 1.26
#![allow(trivial_numeric_casts)]
#![cfg_attr(test, deny(warnings))]
#[cfg(target_os = "redox")] extern crate syscall;
#[cfg(unix)] extern crate libc;
#[cfg(windows)] extern crate winapi;
#[cfg(feature = "rustc-serialize")] extern crate rustc_serialize;
@ -280,14 +281,14 @@ impl Add<Duration> for SteadyTime {
}
}
#[cfg(not(windows))]
#[cfg(not(any(windows, target_env = "sgx")))]
pub fn tzset() {
extern { fn tzset(); }
unsafe { tzset() }
}
#[cfg(windows)]
#[cfg(any(windows, target_env = "sgx"))]
pub fn tzset() {}
/// Holds a calendar date and time broken down into its components (year, month,
@ -551,6 +552,7 @@ pub enum ParseError {
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
#[allow(deprecated)]
match *self {
InvalidFormatSpecifier(ch) => {
write!(f, "{}: %{}", self.description(), ch)
@ -652,7 +654,10 @@ mod tests {
use super::ParseError::{InvalidTime, InvalidYear, MissingFormatConverter,
InvalidFormatSpecifier};
use std::sync::{Once, ONCE_INIT, Mutex, MutexGuard, LockResult};
#[allow(deprecated)] // `Once::new` is const starting in Rust 1.32
use std::sync::ONCE_INIT;
use std::sync::{Once, Mutex, MutexGuard, LockResult};
use std::i32;
use std::mem;
struct TzReset {
@ -664,6 +669,7 @@ mod tests {
// Lock manages current timezone because some tests require LA some
// London
static mut LOCK: *mut Mutex<()> = 0 as *mut _;
#[allow(deprecated)] // `Once::new` is const starting in Rust 1.32
static INIT: Once = ONCE_INIT;
unsafe {
@ -694,8 +700,8 @@ mod tests {
#[test]
fn test_get_time() {
static SOME_RECENT_DATE: i64 = 1325376000i64; // 2012-01-01T00:00:00Z
static SOME_FUTURE_DATE: i64 = 1577836800i64; // 2020-01-01T00:00:00Z
static SOME_RECENT_DATE: i64 = 1577836800i64; // 2020-01-01T00:00:00Z
static SOME_FUTURE_DATE: i64 = i32::MAX as i64; // Y2038
let tv1 = get_time();
debug!("tv1={} sec + {} nsec", tv1.sec, tv1.nsec);

5
third_party/rust/time/src/parse.rs поставляемый
Просмотреть файл

@ -20,10 +20,10 @@ pub fn strptime(mut s: &str, format: &str) -> Result<Tm, ParseError> {
while let Some(ch) = chars.next() {
if ch == '%' {
if let Some(ch) = chars.next() {
try!(parse_type(&mut s, ch, &mut tm));
parse_type(&mut s, ch, &mut tm)?;
}
} else {
try!(parse_char(&mut s, ch));
parse_char(&mut s, ch)?;
}
}
@ -326,6 +326,7 @@ fn match_digits_i64(ss: &mut &str, min_digits : usize, max_digits: usize, ws: bo
let mut value : i64 = 0;
let mut n = 0;
if ws {
#[allow(deprecated)] // use `trim_start_matches` starting in 1.30
let s2 = ss.trim_left_matches(" ");
n = ss.len() - s2.len();
if n > max_digits { return None }

156
third_party/rust/time/src/sys.rs поставляемый
Просмотреть файл

@ -4,7 +4,7 @@ pub use self::inner::*;
#[cfg(any(
all(target_arch = "wasm32", not(target_os = "emscripten")),
target_os = "redox",
target_env = "sgx"
))]
mod common {
use Tm;
@ -133,16 +133,21 @@ mod inner {
}
}
#[cfg(target_os = "redox")]
#[cfg(target_env = "sgx")]
mod inner {
use std::fmt;
use std::cmp::Ordering;
use std::ops::{Add, Sub};
use syscall;
use super::common::{time_to_tm, tm_to_time};
use Duration;
use Tm;
use Duration;
use super::common::{time_to_tm, tm_to_time};
use std::time::SystemTime;
/// The number of nanoseconds in seconds.
const NANOS_PER_SEC: u64 = 1_000_000_000;
#[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
pub struct SteadyTime {
t: Duration
}
pub fn time_to_utc_tm(sec: i64, tm: &mut Tm) {
time_to_tm(sec, tm);
@ -163,111 +168,47 @@ mod inner {
}
pub fn get_time() -> (i64, i32) {
let mut tv = syscall::TimeSpec { tv_sec: 0, tv_nsec: 0 };
syscall::clock_gettime(syscall::CLOCK_REALTIME, &mut tv).unwrap();
(tv.tv_sec as i64, tv.tv_nsec as i32)
SteadyTime::now().t.raw()
}
pub fn get_precise_ns() -> u64 {
let mut ts = syscall::TimeSpec { tv_sec: 0, tv_nsec: 0 };
syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut ts).unwrap();
(ts.tv_sec as u64) * 1000000000 + (ts.tv_nsec as u64)
}
#[derive(Copy)]
pub struct SteadyTime {
t: syscall::TimeSpec,
}
impl fmt::Debug for SteadyTime {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "SteadyTime {{ tv_sec: {:?}, tv_nsec: {:?} }}",
self.t.tv_sec, self.t.tv_nsec)
}
}
impl Clone for SteadyTime {
fn clone(&self) -> SteadyTime {
SteadyTime { t: self.t }
}
// This unwrap is safe because current time is well ahead of UNIX_EPOCH, unless system
// clock is adjusted backward.
let std_duration = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
std_duration.as_secs() * NANOS_PER_SEC + std_duration.subsec_nanos() as u64
}
impl SteadyTime {
pub fn now() -> SteadyTime {
let mut t = SteadyTime {
t: syscall::TimeSpec {
tv_sec: 0,
tv_nsec: 0,
}
};
syscall::clock_gettime(syscall::CLOCK_MONOTONIC, &mut t.t).unwrap();
t
// This unwrap is safe because current time is well ahead of UNIX_EPOCH, unless system
// clock is adjusted backward.
let std_duration = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
// This unwrap is safe because duration is well within the limits of i64.
let duration = Duration::from_std(std_duration).unwrap();
SteadyTime { t: duration }
}
}
impl Sub for SteadyTime {
type Output = Duration;
fn sub(self, other: SteadyTime) -> Duration {
if self.t.tv_nsec >= other.t.tv_nsec {
Duration::seconds(self.t.tv_sec as i64 - other.t.tv_sec as i64) +
Duration::nanoseconds(self.t.tv_nsec as i64 - other.t.tv_nsec as i64)
} else {
Duration::seconds(self.t.tv_sec as i64 - 1 - other.t.tv_sec as i64) +
Duration::nanoseconds(self.t.tv_nsec as i64 + ::NSEC_PER_SEC as i64 -
other.t.tv_nsec as i64)
}
self.t - other.t
}
}
impl Sub<Duration> for SteadyTime {
type Output = SteadyTime;
fn sub(self, other: Duration) -> SteadyTime {
self + -other
SteadyTime { t: self.t - other }
}
}
impl Add<Duration> for SteadyTime {
type Output = SteadyTime;
fn add(mut self, other: Duration) -> SteadyTime {
let seconds = other.num_seconds();
let nanoseconds = other - Duration::seconds(seconds);
let nanoseconds = nanoseconds.num_nanoseconds().unwrap();
self.t.tv_sec += seconds;
self.t.tv_nsec += nanoseconds as i32;
if self.t.tv_nsec >= ::NSEC_PER_SEC {
self.t.tv_nsec -= ::NSEC_PER_SEC;
self.t.tv_sec += 1;
} else if self.t.tv_nsec < 0 {
self.t.tv_sec -= 1;
self.t.tv_nsec += ::NSEC_PER_SEC;
}
self
fn add(self, other: Duration) -> SteadyTime {
SteadyTime { t: self.t + other }
}
}
impl PartialOrd for SteadyTime {
fn partial_cmp(&self, other: &SteadyTime) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for SteadyTime {
fn cmp(&self, other: &SteadyTime) -> Ordering {
match self.t.tv_sec.cmp(&other.t.tv_sec) {
Ordering::Equal => self.t.tv_nsec.cmp(&other.t.tv_nsec),
ord => ord
}
}
}
impl PartialEq for SteadyTime {
fn eq(&self, other: &SteadyTime) -> bool {
self.t.tv_sec == other.t.tv_sec &&
self.t.tv_nsec == other.t.tv_nsec
}
}
impl Eq for SteadyTime {}
}
#[cfg(unix)]
@ -282,7 +223,7 @@ mod inner {
#[cfg(all(not(target_os = "macos"), not(target_os = "ios")))]
pub use self::unix::*;
#[cfg(target_os = "solaris")]
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
extern {
static timezone: time_t;
static altzone: time_t;
@ -313,7 +254,7 @@ mod inner {
rust_tm.tm_utcoff = utcoff;
}
#[cfg(any(target_os = "nacl", target_os = "solaris"))]
#[cfg(any(target_os = "nacl", target_os = "solaris", target_os = "illumos"))]
unsafe fn timegm(tm: *mut libc::tm) -> time_t {
use std::env::{set_var, var_os, remove_var};
extern {
@ -356,7 +297,7 @@ mod inner {
if libc::localtime_r(&sec, &mut out).is_null() {
panic!("localtime_r failed: {}", io::Error::last_os_error());
}
#[cfg(target_os = "solaris")]
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
let gmtoff = {
::tzset();
// < 0 means we don't know; assume we're not in DST.
@ -369,7 +310,7 @@ mod inner {
-timezone
}
};
#[cfg(not(target_os = "solaris"))]
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
let gmtoff = out.tm_gmtoff;
tm_to_rust_tm(&out, gmtoff as i32, tm);
}
@ -378,7 +319,12 @@ mod inner {
pub fn utc_tm_to_time(rust_tm: &Tm) -> i64 {
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
use libc::timegm64 as timegm;
#[cfg(not(any(all(target_os = "android", target_pointer_width = "32"), target_os = "nacl", target_os = "solaris")))]
#[cfg(not(any(
all(target_os = "android", target_pointer_width = "32"),
target_os = "nacl",
target_os = "solaris",
target_os = "illumos"
)))]
use libc::timegm;
let mut tm = unsafe { mem::zeroed() };
@ -394,11 +340,14 @@ mod inner {
#[cfg(any(target_os = "macos", target_os = "ios"))]
mod mac {
#[allow(deprecated)]
use libc::{self, timeval, mach_timebase_info};
#[allow(deprecated)]
use std::sync::{Once, ONCE_INIT};
use std::ops::{Add, Sub};
use Duration;
#[allow(deprecated)]
fn info() -> &'static mach_timebase_info {
static mut INFO: mach_timebase_info = mach_timebase_info {
numer: 0,
@ -421,6 +370,7 @@ mod inner {
(tv.tv_sec as i64, tv.tv_usec * 1000)
}
#[allow(deprecated)]
#[inline]
pub fn get_precise_ns() -> u64 {
unsafe {
@ -615,6 +565,7 @@ mod inner {
mod inner {
use std::io;
use std::mem;
#[allow(deprecated)]
use std::sync::{Once, ONCE_INIT};
use std::ops::{Add, Sub};
use {Tm, Duration};
@ -628,6 +579,7 @@ mod inner {
fn frequency() -> i64 {
static mut FREQUENCY: i64 = 0;
#[allow(deprecated)]
static ONCE: Once = ONCE_INIT;
unsafe {
@ -903,10 +855,10 @@ mod inner {
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724944%28v=vs.85%29.aspx
#[cfg(test)]
fn acquire_privileges() {
use std::sync::{ONCE_INIT, Once};
use winapi::um::processthreadsapi::*;
use winapi::um::winbase::LookupPrivilegeValueA;
const SE_PRIVILEGE_ENABLED: DWORD = 2;
#[allow(deprecated)]
static INIT: Once = ONCE_INIT;
// TODO: FIXME
@ -917,26 +869,20 @@ mod inner {
) -> BOOL;
}
#[repr(C)]
struct TKP {
tkp: TOKEN_PRIVILEGES,
laa: LUID_AND_ATTRIBUTES,
}
INIT.call_once(|| unsafe {
let mut hToken = 0 as *mut _;
call!(OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
&mut hToken));
let mut tkp = mem::zeroed::<TKP>();
assert_eq!(tkp.tkp.Privileges.len(), 0);
let mut tkp = mem::zeroed::<TOKEN_PRIVILEGES>();
assert_eq!(tkp.Privileges.len(), 1);
let c = ::std::ffi::CString::new("SeTimeZonePrivilege").unwrap();
call!(LookupPrivilegeValueA(0 as *const _, c.as_ptr(),
&mut tkp.laa.Luid));
tkp.tkp.PrivilegeCount = 1;
tkp.laa.Attributes = SE_PRIVILEGE_ENABLED;
call!(AdjustTokenPrivileges(hToken, FALSE, &mut tkp.tkp, 0,
&mut tkp.Privileges[0].Luid));
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
tkp.PrivilegeCount = 1;
call!(AdjustTokenPrivileges(hToken, FALSE, &mut tkp, 0,
0 as *mut _, 0 as *mut _));
});
}