#[repr(transparent)]pub struct DateTime<U: TimeUnitTrait = Nanosecond>(pub i64, _);Expand description
Represents a date and time with a specific time unit precision.
§Type Parameters
U: The time unit precision, defaulting toNanosecond. Must implementTimeUnitTrait.
§Fields
0: Ani64representing the timestamp in the specified time unit.PhantomData<U>: A zero-sized type used to “mark” the time unit without affecting the struct’s memory layout.
Tuple Fields§
§0: i64Implementations§
source§impl<U: TimeUnitTrait> DateTime<U>
impl<U: TimeUnitTrait> DateTime<U>
sourcepub const fn is_nat(&self) -> bool
pub const fn is_nat(&self) -> bool
Checks if the DateTime instance represents “Not-a-Time” (NaT).
§Returns
true if the instance is NaT, false otherwise.
sourcepub const fn is_not_nat(&self) -> bool
pub const fn is_not_nat(&self) -> bool
Checks if the DateTime instance represents a valid time (not NaT).
§Returns
true if the instance is not NaT, false otherwise.
sourcepub const fn nat() -> Self
pub const fn nat() -> Self
Creates a new DateTime instance representing “Not-a-Time” (NaT).
§Returns
A new DateTime<U> instance representing NaT.
sourcepub const fn from_opt_i64(v: Option<i64>) -> Self
pub const fn from_opt_i64(v: Option<i64>) -> Self
sourcepub const fn into_opt_i64(self) -> Option<i64>
pub const fn into_opt_i64(self) -> Option<i64>
Converts the DateTime instance to an optional i64 timestamp.
§Returns
Some(i64) if the instance is not NaT, None otherwise.
sourcepub fn to_cr(&self) -> Option<CrDateTime<Utc>>
👎Deprecated since 0.5.0: use as_cr instead
pub fn to_cr(&self) -> Option<CrDateTime<Utc>>
as_cr insteadConverts the DateTime instance to a chrono::DateTime<Utc>.
§Returns
Some(CrDateTime<Utc>) if the conversion is successful, None if the instance is NaT.
pub fn as_cr(&self) -> Option<CrDateTime<Utc>>
sourcepub fn duration_trunc(self, duration: TimeDelta) -> Selfwhere
Self: TryInto<CrDateTime<Utc>> + From<CrDateTime<Utc>>,
<Self as TryInto<CrDateTime<Utc>>>::Error: Debug,
pub fn duration_trunc(self, duration: TimeDelta) -> Selfwhere
Self: TryInto<CrDateTime<Utc>> + From<CrDateTime<Utc>>,
<Self as TryInto<CrDateTime<Utc>>>::Error: Debug,
source§impl<U: TimeUnitTrait> DateTime<U>
impl<U: TimeUnitTrait> DateTime<U>
sourcepub fn time(&self) -> Option<NaiveTime>
pub fn time(&self) -> Option<NaiveTime>
Returns the time component of the DateTime as a NaiveTime.
§Returns
Option<NaiveTime>: The time component if the DateTime is valid, or None if it’s NaT.
sourcepub fn day(&self) -> Option<usize>
pub fn day(&self) -> Option<usize>
Returns the day of the month (1-31).
§Returns
Option<usize>: The day of the month if the DateTime is valid, or None if it’s NaT.
sourcepub fn month(&self) -> Option<usize>
pub fn month(&self) -> Option<usize>
Returns the month (1-12).
§Returns
Option<usize>: The month if the DateTime is valid, or None if it’s NaT.
sourcepub fn hour(&self) -> Option<usize>
pub fn hour(&self) -> Option<usize>
Returns the hour (0-23).
§Returns
Option<usize>: The hour if the DateTime is valid, or None if it’s NaT.
source§impl<U: TimeUnitTrait> DateTime<U>
impl<U: TimeUnitTrait> DateTime<U>
pub fn into_unit<T: TimeUnitTrait>(self) -> DateTime<T>
Trait Implementations§
source§impl<U: TimeUnitTrait> Debug for DateTime<U>
impl<U: TimeUnitTrait> Debug for DateTime<U>
source§impl<U: TimeUnitTrait> Default for DateTime<U>
impl<U: TimeUnitTrait> Default for DateTime<U>
source§impl From<DateTime<Utc>> for DateTime<Nanosecond>
impl From<DateTime<Utc>> for DateTime<Nanosecond>
source§fn from(dt: CrDateTime<Utc>) -> Self
fn from(dt: CrDateTime<Utc>) -> Self
source§impl From<DateTime<Utc>> for DateTime<Microsecond>
impl From<DateTime<Utc>> for DateTime<Microsecond>
source§fn from(dt: CrDateTime<Utc>) -> Self
fn from(dt: CrDateTime<Utc>) -> Self
source§impl From<DateTime<Utc>> for DateTime<Millisecond>
impl From<DateTime<Utc>> for DateTime<Millisecond>
source§fn from(dt: CrDateTime<Utc>) -> Self
fn from(dt: CrDateTime<Utc>) -> Self
source§impl From<DateTime<Utc>> for DateTime<Second>
impl From<DateTime<Utc>> for DateTime<Second>
source§fn from(dt: CrDateTime<Utc>) -> Self
fn from(dt: CrDateTime<Utc>) -> Self
source§impl<U: TimeUnitTrait> From<NaiveDateTime> for DateTime<U>
impl<U: TimeUnitTrait> From<NaiveDateTime> for DateTime<U>
source§fn from(dt: NaiveDateTime) -> Self
fn from(dt: NaiveDateTime) -> Self
source§impl<U: TimeUnitTrait> From<Option<NaiveDateTime>> for DateTime<U>
impl<U: TimeUnitTrait> From<Option<NaiveDateTime>> for DateTime<U>
source§fn from(dt: Option<NaiveDateTime>) -> Self
fn from(dt: Option<NaiveDateTime>) -> Self
source§impl<U: TimeUnitTrait> FromStr for DateTime<U>
impl<U: TimeUnitTrait> FromStr for DateTime<U>
source§impl<U: Ord + TimeUnitTrait> Ord for DateTime<U>
impl<U: Ord + TimeUnitTrait> Ord for DateTime<U>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<U: PartialOrd + TimeUnitTrait> PartialOrd for DateTime<U>
impl<U: PartialOrd + TimeUnitTrait> PartialOrd for DateTime<U>
source§impl<U: TimeUnitTrait> Sub for DateTime<U>
impl<U: TimeUnitTrait> Sub for DateTime<U>
impl<U: Copy + TimeUnitTrait> Copy for DateTime<U>
impl<U: Eq + TimeUnitTrait> Eq for DateTime<U>
impl<U: TimeUnitTrait> Send for DateTime<U>
impl<U: TimeUnitTrait> StructuralPartialEq for DateTime<U>
impl<U: TimeUnitTrait> Sync for DateTime<U>
Auto Trait Implementations§
impl<U> Freeze for DateTime<U>
impl<U> RefUnwindSafe for DateTime<U>where
U: RefUnwindSafe,
impl<U> Unpin for DateTime<U>where
U: Unpin,
impl<U> UnwindSafe for DateTime<U>where
U: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)