scsys_core/time/
mod.rs

1/*
2    Appellation: time <module>
3    Contrib: FL03 <jo3mccain@icloud.com>
4*/
5//! # Time
6//!
7//! The `time` module provides a set of utilities for working with time and timestamps.
8#[allow(unused_imports)]
9#[doc(inline)]
10pub use self::{epoch::Epoch, timestamp::Timestamp, utils::*};
11
12#[doc(hidden)]
13pub mod datetime;
14pub mod epoch;
15pub mod timestamp;
16
17pub(crate) mod prelude {
18    pub use super::Now;
19    pub use super::epoch::Epoch;
20    pub use super::timestamp::Timestamp;
21    #[allow(unused_imports)]
22    pub use super::utils::*;
23}
24
25/// The [`Now`] trait provides a common creation routines for all datetime implementations.
26pub trait Now {
27    type Output;
28
29    fn now() -> Self::Output;
30}
31
32pub(crate) mod utils {
33    /// [systime] is a utilitarian function that returns the current system time in milliseconds.
34    #[cfg(feature = "std")]
35    #[inline]
36    pub fn systime() -> core::time::Duration {
37        std::time::SystemTime::now()
38            .duration_since(std::time::UNIX_EPOCH)
39            .unwrap()
40    }
41    /// [systime] is a utilitarian function that returns the current system time in milliseconds.
42    #[cfg(feature = "std")]
43    #[inline]
44    pub fn std_time() -> u128 {
45        systime().as_millis()
46    }
47}