mirror of
https://github.com/chronotope/chrono.git
synced 2025-10-02 15:26:12 +00:00
Move sys module into offset, which is the only place using it
This commit is contained in:
parent
29cbd5945c
commit
5f59b2c24f
@ -429,12 +429,6 @@ mod oldtime;
|
|||||||
// this reexport is to aid the transition and should not be in the prelude!
|
// this reexport is to aid the transition and should not be in the prelude!
|
||||||
pub use oldtime::Duration;
|
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(feature = "__doctest")]
|
||||||
#[cfg_attr(feature = "__doctest", cfg(doctest))]
|
#[cfg_attr(feature = "__doctest", cfg(doctest))]
|
||||||
use doc_comment::doctest;
|
use doc_comment::doctest;
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
use rkyv::{Archive, Deserialize, Serialize};
|
use rkyv::{Archive, Deserialize, Serialize};
|
||||||
|
|
||||||
use super::fixed::FixedOffset;
|
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};
|
use super::{LocalResult, TimeZone};
|
||||||
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))]
|
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))]
|
||||||
use crate::naive::NaiveTime;
|
use crate::naive::NaiveTime;
|
||||||
use crate::naive::{NaiveDate, NaiveDateTime};
|
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};
|
use crate::{Date, DateTime};
|
||||||
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))]
|
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))]
|
||||||
use crate::{Datelike, Timelike};
|
use crate::{Datelike, Timelike};
|
||||||
|
@ -25,6 +25,12 @@ use crate::naive::{NaiveDate, NaiveDateTime, NaiveTime};
|
|||||||
use crate::Weekday;
|
use crate::Weekday;
|
||||||
use crate::{Date, DateTime};
|
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.
|
/// The conversion result from the local time to the timezone-aware datetime types.
|
||||||
#[derive(Clone, PartialEq, Debug, Copy, Eq, Hash)]
|
#[derive(Clone, PartialEq, Debug, Copy, Eq, Hash)]
|
||||||
pub enum LocalResult<T> {
|
pub enum LocalResult<T> {
|
||||||
|
@ -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
|
/// For example a timespec of 1.2 seconds after the beginning of the epoch would
|
||||||
/// be represented as {sec: 1, nsec: 200000000}.
|
/// be represented as {sec: 1, nsec: 200000000}.
|
||||||
pub(crate) struct Timespec {
|
pub(super) struct Timespec {
|
||||||
pub(crate) sec: i64,
|
sec: i64,
|
||||||
pub(crate) nsec: i32,
|
nsec: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Timespec {
|
impl Timespec {
|
||||||
/// Constructs a timespec representing the current time in UTC.
|
/// Constructs a timespec representing the current time in UTC.
|
||||||
pub(crate) fn now() -> Timespec {
|
pub(super) fn now() -> Timespec {
|
||||||
let st =
|
let st =
|
||||||
SystemTime::now().duration_since(UNIX_EPOCH).expect("system time before Unix epoch");
|
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 }
|
Timespec { sec: st.as_secs() as i64, nsec: st.subsec_nanos() as i32 }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts this timespec into the system's local time.
|
/// 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 {
|
let mut tm = Tm {
|
||||||
tm_sec: 0,
|
tm_sec: 0,
|
||||||
tm_min: 0,
|
tm_min: 0,
|
||||||
@ -118,7 +118,7 @@ pub(crate) struct Tm {
|
|||||||
|
|
||||||
impl Tm {
|
impl Tm {
|
||||||
/// Convert time to the seconds from January 1, 1970
|
/// 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 {
|
let sec = match self.tm_utcoff {
|
||||||
0 => utc_tm_to_time(self),
|
0 => utc_tm_to_time(self),
|
||||||
_ => local_tm_to_time(self),
|
_ => local_tm_to_time(self),
|
Loading…
x
Reference in New Issue
Block a user