Move sys module into offset, which is the only place using it

This commit is contained in:
Dirkjan Ochtman 2022-04-07 15:15:09 +02:00
parent 29cbd5945c
commit 5f59b2c24f
7 changed files with 14 additions and 14 deletions

View File

@ -429,12 +429,6 @@ mod oldtime;
// this reexport is to aid the transition and should not be in the prelude!
pub use oldtime::Duration;
#[cfg(all(
feature = "clock",
not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))
))]
mod sys;
#[cfg(feature = "__doctest")]
#[cfg_attr(feature = "__doctest", cfg(doctest))]
use doc_comment::doctest;

View File

@ -7,12 +7,12 @@
use rkyv::{Archive, Deserialize, Serialize};
use super::fixed::FixedOffset;
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))]
use super::sys::{self, Timespec};
use super::{LocalResult, TimeZone};
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))]
use crate::naive::NaiveTime;
use crate::naive::{NaiveDate, NaiveDateTime};
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))]
use crate::sys::{self, Timespec};
use crate::{Date, DateTime};
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))]
use crate::{Datelike, Timelike};

View File

@ -25,6 +25,12 @@ use crate::naive::{NaiveDate, NaiveDateTime, NaiveTime};
use crate::Weekday;
use crate::{Date, DateTime};
#[cfg(all(
feature = "clock",
not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))
))]
mod sys;
/// The conversion result from the local time to the timezone-aware datetime types.
#[derive(Clone, PartialEq, Debug, Copy, Eq, Hash)]
pub enum LocalResult<T> {

View File

@ -35,21 +35,21 @@ use inner::{local_tm_to_time, time_to_local_tm, utc_tm_to_time};
///
/// For example a timespec of 1.2 seconds after the beginning of the epoch would
/// be represented as {sec: 1, nsec: 200000000}.
pub(crate) struct Timespec {
pub(crate) sec: i64,
pub(crate) nsec: i32,
pub(super) struct Timespec {
sec: i64,
nsec: i32,
}
impl Timespec {
/// Constructs a timespec representing the current time in UTC.
pub(crate) fn now() -> Timespec {
pub(super) fn now() -> Timespec {
let st =
SystemTime::now().duration_since(UNIX_EPOCH).expect("system time before Unix epoch");
Timespec { sec: st.as_secs() as i64, nsec: st.subsec_nanos() as i32 }
}
/// Converts this timespec into the system's local time.
pub(crate) fn local(self) -> Tm {
pub(super) fn local(self) -> Tm {
let mut tm = Tm {
tm_sec: 0,
tm_min: 0,
@ -118,7 +118,7 @@ pub(crate) struct Tm {
impl Tm {
/// Convert time to the seconds from January 1, 1970
pub(crate) fn to_timespec(&self) -> Timespec {
pub(super) fn to_timespec(&self) -> Timespec {
let sec = match self.tm_utcoff {
0 => utc_tm_to_time(self),
_ => local_tm_to_time(self),