From ef9ae30ca213b4089afb86926fc893f1809e3380 Mon Sep 17 00:00:00 2001 From: Kevin Flansburg Date: Sun, 17 Oct 2021 21:44:35 -0400 Subject: [PATCH] Remove use of localtime_r, and all dependent callsights --- src/lib.rs | 2 +- src/offset/local.rs | 54 ++++++++++++++++++++++----------------------- src/sys.rs | 38 +++++++++++++++---------------- src/sys/unix.rs | 50 ++++++++++++++++++++--------------------- 4 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9d66ae3249..333a81d327 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -414,7 +414,7 @@ #![cfg_attr(feature = "bench", feature(test))] // lib stability features as per RFC #507 #![deny(missing_docs)] #![deny(missing_debug_implementations)] -#![deny(dead_code)] +// #![deny(dead_code)] // lints are added all the time, we test on 1.13 #![allow(unknown_lints)] #![cfg_attr(not(any(feature = "std", test)), no_std)] diff --git a/src/offset/local.rs b/src/offset/local.rs index 1abb3a9db0..4e92dc45fa 100644 --- a/src/offset/local.rs +++ b/src/offset/local.rs @@ -91,16 +91,16 @@ fn datetime_to_timespec(d: &NaiveDateTime, local: bool) -> sys::Timespec { pub struct Local; impl Local { - /// Returns a `Date` which corresponds to the current date. - pub fn today() -> Date { - Local::now().date() - } + // /// Returns a `Date` which corresponds to the current date. + // pub fn today() -> Date { + // Local::now().date() + // } - /// Returns a `DateTime` which corresponds to the current date. - #[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))] - pub fn now() -> DateTime { - tm_to_datetime(Timespec::now().local()) - } + // /// Returns a `DateTime` which corresponds to the current date. + // #[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))] + // pub fn now() -> DateTime { + // tm_to_datetime(Timespec::now().local()) + // } /// Returns a `DateTime` which corresponds to the current date. #[cfg(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))] @@ -156,17 +156,17 @@ impl TimeZone for Local { LocalResult::Single(DateTime::from_utc(local, offset)) } - #[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))] - fn from_local_datetime(&self, local: &NaiveDateTime) -> LocalResult> { - let timespec = datetime_to_timespec(local, true); + // #[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))] + // fn from_local_datetime(&self, local: &NaiveDateTime) -> LocalResult> { + // let timespec = datetime_to_timespec(local, true); - // datetime_to_timespec completely ignores leap seconds, so we need to adjust for them - let mut tm = timespec.local(); - assert_eq!(tm.tm_nsec, 0); - tm.tm_nsec = local.nanosecond() as i32; + // // datetime_to_timespec completely ignores leap seconds, so we need to adjust for them + // let mut tm = timespec.local(); + // assert_eq!(tm.tm_nsec, 0); + // tm.tm_nsec = local.nanosecond() as i32; - LocalResult::Single(tm_to_datetime(tm)) - } + // LocalResult::Single(tm_to_datetime(tm)) + // } fn from_utc_date(&self, utc: &NaiveDate) -> Date { let midnight = self.from_utc_datetime(&utc.and_hms(0, 0, 0)); @@ -180,17 +180,17 @@ impl TimeZone for Local { DateTime::from_utc(*utc, offset) } - #[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))] - fn from_utc_datetime(&self, utc: &NaiveDateTime) -> DateTime { - let timespec = datetime_to_timespec(utc, false); + // #[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))] + // fn from_utc_datetime(&self, utc: &NaiveDateTime) -> DateTime { + // let timespec = datetime_to_timespec(utc, false); - // datetime_to_timespec completely ignores leap seconds, so we need to adjust for them - let mut tm = timespec.local(); - assert_eq!(tm.tm_nsec, 0); - tm.tm_nsec = utc.nanosecond() as i32; + // // datetime_to_timespec completely ignores leap seconds, so we need to adjust for them + // let mut tm = timespec.local(); + // assert_eq!(tm.tm_nsec, 0); + // tm.tm_nsec = utc.nanosecond() as i32; - tm_to_datetime(tm) - } + // tm_to_datetime(tm) + // } } #[cfg(test)] diff --git a/src/sys.rs b/src/sys.rs index 2e46b7e8eb..e2d469de4a 100644 --- a/src/sys.rs +++ b/src/sys.rs @@ -46,25 +46,25 @@ impl Timespec { Timespec { sec: st.as_secs() as i64, nsec: st.subsec_nanos() as i32 } } - /// Converts this timespec into the system's local time. - pub fn local(self) -> Tm { - let mut tm = Tm { - tm_sec: 0, - tm_min: 0, - tm_hour: 0, - tm_mday: 0, - tm_mon: 0, - tm_year: 0, - tm_wday: 0, - tm_yday: 0, - tm_isdst: 0, - tm_utcoff: 0, - tm_nsec: 0, - }; - inner::time_to_local_tm(self.sec, &mut tm); - tm.tm_nsec = self.nsec; - tm - } + // /// Converts this timespec into the system's local time. + // pub fn local(self) -> Tm { + // let mut tm = Tm { + // tm_sec: 0, + // tm_min: 0, + // tm_hour: 0, + // tm_mday: 0, + // tm_mon: 0, + // tm_year: 0, + // tm_wday: 0, + // tm_yday: 0, + // tm_isdst: 0, + // tm_utcoff: 0, + // tm_nsec: 0, + // }; + // inner::time_to_local_tm(self.sec, &mut tm); + // tm.tm_nsec = self.nsec; + // tm + // } } /// Holds a calendar date and time broken down into its components (year, month, diff --git a/src/sys/unix.rs b/src/sys/unix.rs index 2f845e7455..c528dd53e6 100644 --- a/src/sys/unix.rs +++ b/src/sys/unix.rs @@ -77,31 +77,31 @@ unsafe fn timegm(tm: *mut libc::tm) -> time_t { ret } -pub fn time_to_local_tm(sec: i64, tm: &mut Tm) { - unsafe { - let sec = sec as time_t; - let mut out = mem::zeroed(); - if libc::localtime_r(&sec, &mut out).is_null() { - panic!("localtime_r failed: {}", io::Error::last_os_error()); - } - #[cfg(any(target_os = "solaris", target_os = "illumos"))] - let gmtoff = { - tzset(); - // < 0 means we don't know; assume we're not in DST. - if out.tm_isdst == 0 { - // timezone is seconds west of UTC, tm_gmtoff is seconds east - -timezone - } else if out.tm_isdst > 0 { - -altzone - } else { - -timezone - } - }; - #[cfg(not(any(target_os = "solaris", target_os = "illumos")))] - let gmtoff = out.tm_gmtoff; - tm_to_rust_tm(&out, gmtoff as i32, tm); - } -} +// pub fn time_to_local_tm(sec: i64, tm: &mut Tm) { +// unsafe { +// let sec = sec as time_t; +// let mut out = mem::zeroed(); +// if libc::localtime_r(&sec, &mut out).is_null() { +// panic!("localtime_r failed: {}", io::Error::last_os_error()); +// } +// #[cfg(any(target_os = "solaris", target_os = "illumos"))] +// let gmtoff = { +// tzset(); +// // < 0 means we don't know; assume we're not in DST. +// if out.tm_isdst == 0 { +// // timezone is seconds west of UTC, tm_gmtoff is seconds east +// -timezone +// } else if out.tm_isdst > 0 { +// -altzone +// } else { +// -timezone +// } +// }; +// #[cfg(not(any(target_os = "solaris", target_os = "illumos")))] +// let gmtoff = out.tm_gmtoff; +// tm_to_rust_tm(&out, gmtoff as i32, tm); +// } +// } pub fn utc_tm_to_time(rust_tm: &Tm) -> i64 { #[cfg(not(any(