pub struct UtcTime { /* private fields */ }Expand description
A Unix time, i.e. seconds since 1970-01-01 in UTC
Using i64 values as seconds since 1970-01-01, this library will work for the next 292 billion years.
Implementations§
source§impl UtcTime
impl UtcTime
sourcepub const unsafe fn new_unchecked(secs: i64, nanos: u32) -> Self
pub const unsafe fn new_unchecked(secs: i64, nanos: u32) -> Self
sourcepub const fn new(secs: i64, nanos: u32) -> Option<Self>
pub const fn new(secs: i64, nanos: u32) -> Option<Self>
Build a new UtcTime
nanos will be normalized to a values less than 1_000_000_000, the number of nanoseconds in a second.
If the resulting number of seconds will exceed i64::MAX, None is returned.
§Example
// August 3, 2022, about 19 o'clock in the evening in CEST.
let timestamp = UtcTime::new(1_659_545_693, 895_531_827).unwrap();sourcepub fn from_system_time(value: SystemTime) -> Option<Self>
Available on crate feature std only.
pub fn from_system_time(value: SystemTime) -> Option<Self>
std only.Convert a SystemTime
§Example
let system_time = SystemTime::now();
let now = UtcTime::from_system_time(system_time).unwrap();sourcepub const fn from_duration(value: Duration) -> Option<Self>
pub const fn from_duration(value: Duration) -> Option<Self>
sourcepub const fn as_secs(self) -> i64
pub const fn as_secs(self) -> i64
Total number of whole seconds since epoch (1970-01-01 in UTC)
§Example
let now = UtcTime::now().unwrap();
let total_secs = now.as_secs();
assert!(total_secs > 1_658_711_810);
assert!(total_secs < 1_974_324_043); // update before 2032-07-25sourcepub const fn as_millis(self) -> i128
pub const fn as_millis(self) -> i128
Total number of whole milliseconds since epoch (1970-01-01 in UTC)
§Example
let now = UtcTime::now().unwrap();
let total_millis = now.as_millis();
assert!(total_millis > 1_658_711_810_802);
assert!(total_millis < 1_974_324_043_000); // update before 2032-07-25sourcepub const fn as_micros(self) -> i128
pub const fn as_micros(self) -> i128
Total number of whole microseconds since epoch (1970-01-01 in UTC)
§Example
let now = UtcTime::now().unwrap();
let total_micros = now.as_micros();
assert!(total_micros > 1_658_711_810_802_520);
assert!(total_micros < 1_974_324_043_000_000); // update before 2032-07-25sourcepub const fn as_nanos(self) -> i128
pub const fn as_nanos(self) -> i128
Total number of whole nanoseconds since epoch (1970-01-01 in UTC)
§Example
let now = UtcTime::now().unwrap();
let total_nanos = now.as_nanos();
assert!(total_nanos > 1_658_711_810_802_520_027);
assert!(total_nanos < 1_974_324_043_000_000_000); // update before 2032-07-25sourcepub const fn subsec_millis(self) -> u32
pub const fn subsec_millis(self) -> u32
Fractional number of milliseconds since epoch (1970-01-01 in UTC)
§Example
let now = UtcTime::now().unwrap();
let millis = now.subsec_millis();
assert!(millis < 1_000);sourcepub const fn subsec_micros(self) -> u32
pub const fn subsec_micros(self) -> u32
Fractional number of microseconds since epoch (1970-01-01 in UTC)
§Example
let now = UtcTime::now().unwrap();
let micros = now.subsec_micros();
assert!(micros < 1_000_000);sourcepub const fn subsec_nanos(self) -> u32
pub const fn subsec_nanos(self) -> u32
Fractional number of nanoseconds since epoch (1970-01-01 in UTC)
§Example
let now = UtcTime::now().unwrap();
let nanos = now.subsec_nanos();
assert!(nanos < 1_000_000_000);sourcepub const fn into_duration(self) -> Result<Duration, ConversionError>
pub const fn into_duration(self) -> Result<Duration, ConversionError>
sourcepub fn into_system_time(self) -> Result<SystemTime, ConversionError>
Available on crate feature std only.
pub fn into_system_time(self) -> Result<SystemTime, ConversionError>
std only.Convert the timestamp to a SystemTime
§Errors
The conversion won’t succeed if and only if the stored date is earlier than 1970-01-01.
§Example
let now = UtcTime::now().unwrap();
let system_time = now.into_system_time().unwrap();Trait Implementations§
source§impl<'a> Arbitrary<'a> for UtcTime
Available on crate feature arbitrary only.
impl<'a> Arbitrary<'a> for UtcTime
arbitrary only.source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moresource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moresource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moresource§impl Arbitrary for UtcTime
Available on crate feature proptest only.
impl Arbitrary for UtcTime
proptest only.§type Parameters = <(i64, u32) as Arbitrary>::Parameters
type Parameters = <(i64, u32) as Arbitrary>::Parameters
arbitrary_with accepts for configuration
of the generated Strategy. Parameters must implement Default.§type Strategy = Map<<(i64, u32) as Arbitrary>::Strategy, fn(_: (i64, u32)) -> UtcTime>
type Strategy = Map<<(i64, u32) as Arbitrary>::Strategy, fn(_: (i64, u32)) -> UtcTime>
Strategy used to generate values of type Self.source§fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
source§impl Archive for UtcTime
Available on crate feature rkyv only.
impl Archive for UtcTime
rkyv only.source§impl<'de> Deserialize<'de> for UtcTime
Available on crate feature serde only.
impl<'de> Deserialize<'de> for UtcTime
serde only.source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl<D: Fallible + ?Sized> Deserialize<UtcTime, D> for Archived<UtcTime>
Available on crate feature rkyv only.
impl<D: Fallible + ?Sized> Deserialize<UtcTime, D> for Archived<UtcTime>
rkyv only.source§impl Ord for UtcTime
impl Ord for UtcTime
source§impl PartialEq for UtcTime
impl PartialEq for UtcTime
source§impl PartialOrd for UtcTime
impl PartialOrd for UtcTime
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl TryFrom<Duration> for UtcTime
impl TryFrom<Duration> for UtcTime
§type Error = ConversionError
type Error = ConversionError
source§impl TryFrom<SystemTime> for UtcTime
Available on crate feature std only.
impl TryFrom<SystemTime> for UtcTime
std only.§type Error = ConversionError
type Error = ConversionError
source§fn try_from(value: SystemTime) -> Result<Self, ConversionError>
fn try_from(value: SystemTime) -> Result<Self, ConversionError>
source§impl TryFrom<UtcTime> for Duration
impl TryFrom<UtcTime> for Duration
§type Error = ConversionError
type Error = ConversionError
source§impl TryFrom<UtcTime> for SystemTime
Available on crate feature std only.
impl TryFrom<UtcTime> for SystemTime
std only.§type Error = ConversionError
type Error = ConversionError
impl Copy for UtcTime
impl Eq for UtcTime
impl LifetimeFree for UtcTime
castaway only.impl StructuralPartialEq for UtcTime
Auto Trait Implementations§
impl Freeze for UtcTime
impl RefUnwindSafe for UtcTime
impl Send for UtcTime
impl Sync for UtcTime
impl Unpin for UtcTime
impl UnwindSafe for UtcTime
Blanket Implementations§
source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata
source§impl<T> ArchiveUnsized for Twhere
T: Archive,
impl<T> ArchiveUnsized for Twhere
T: Archive,
§type Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
Archive, it may be unsized. Read more