#[repr(transparent)]pub struct DateTime<U = Nanosecond>(pub i64, _)
where
U: TimeUnitTrait;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> DateTime<U>where
U: TimeUnitTrait,
impl<U> DateTime<U>where
U: TimeUnitTrait,
sourcepub fn is_nat(&self) -> bool
pub 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 fn is_not_nat(&self) -> bool
pub 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 fn nat() -> DateTime<U>
pub fn nat() -> DateTime<U>
Creates a new DateTime instance representing “Not-a-Time” (NaT).
§Returns
A new DateTime<U> instance representing NaT.
sourcepub fn from_opt_i64(v: Option<i64>) -> DateTime<U>
pub fn from_opt_i64(v: Option<i64>) -> DateTime<U>
sourcepub fn into_opt_i64(self) -> Option<i64>
pub 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<DateTime<Utc>>
pub fn to_cr(&self) -> Option<DateTime<Utc>>
Converts the DateTime instance to a chrono::DateTime<Utc>.
§Returns
Some(CrDateTime<Utc>) if the conversion is successful, None if the instance is NaT.
sourcepub fn duration_trunc(self, duration: TimeDelta) -> DateTime<U>
pub fn duration_trunc(self, duration: TimeDelta) -> DateTime<U>
source§impl<U> DateTime<U>
impl<U> 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> DateTime<U>where
U: TimeUnitTrait,
impl<U> DateTime<U>where
U: TimeUnitTrait,
pub fn into_unit<T>(self) -> DateTime<T>where
T: TimeUnitTrait,
Trait Implementations§
source§impl Cast<DateTime<Microsecond>> for DateTime<Nanosecond>
impl Cast<DateTime<Microsecond>> for DateTime<Nanosecond>
fn cast(self) -> DateTime<Microsecond>
source§impl Cast<DateTime<Microsecond>> for DateTime<Millisecond>
impl Cast<DateTime<Microsecond>> for DateTime<Millisecond>
fn cast(self) -> DateTime<Microsecond>
source§impl Cast<DateTime<Microsecond>> for DateTime<Second>
impl Cast<DateTime<Microsecond>> for DateTime<Second>
fn cast(self) -> DateTime<Microsecond>
source§impl Cast<DateTime<Millisecond>> for DateTime<Nanosecond>
impl Cast<DateTime<Millisecond>> for DateTime<Nanosecond>
fn cast(self) -> DateTime<Millisecond>
source§impl Cast<DateTime<Millisecond>> for DateTime<Microsecond>
impl Cast<DateTime<Millisecond>> for DateTime<Microsecond>
fn cast(self) -> DateTime<Millisecond>
source§impl Cast<DateTime<Millisecond>> for DateTime<Second>
impl Cast<DateTime<Millisecond>> for DateTime<Second>
fn cast(self) -> DateTime<Millisecond>
source§impl<U> Default for DateTime<U>where
U: TimeUnitTrait,
impl<U> Default for DateTime<U>where
U: TimeUnitTrait,
source§impl<U> From<NaiveDateTime> for DateTime<U>
impl<U> From<NaiveDateTime> for DateTime<U>
source§fn from(dt: NaiveDateTime) -> DateTime<U>
fn from(dt: NaiveDateTime) -> DateTime<U>
source§impl<U: TimeUnitTrait> GetDataType for DateTime<U>
impl<U: TimeUnitTrait> GetDataType for DateTime<U>
source§impl<Unit: TimeUnitTrait> IsNone for DateTime<Unit>
impl<Unit: TimeUnitTrait> IsNone for DateTime<Unit>
type Inner = DateTime<Unit>
type Cast<U: IsNone<Inner = U> + Clone> = U
source§fn to_opt(self) -> Option<Self::Inner>
fn to_opt(self) -> Option<Self::Inner>
Option<Self::Inner>. Read moresource§fn as_opt(&self) -> Option<&Self::Inner>
fn as_opt(&self) -> Option<&Self::Inner>
Option<&Self::Inner>. Read moresource§fn from_inner(inner: Self::Inner) -> Self
fn from_inner(inner: Self::Inner) -> Self
Self from the given inner value. Read morefn unwrap(self) -> Self::Inner
source§fn map<F, U: IsNone>(self, f: F) -> U
fn map<F, U: IsNone>(self, f: F) -> U
Self, if it exists. Read moresource§fn from_opt(opt: Option<Self::Inner>) -> Self
fn from_opt(opt: Option<Self::Inner>) -> Self
Self from an Option<Self::Inner>.fn not_none(&self) -> bool
source§impl<U> Ord for DateTime<U>where
U: Ord + TimeUnitTrait,
impl<U> Ord for DateTime<U>where
U: Ord + TimeUnitTrait,
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<U> PartialOrd for DateTime<U>where
U: PartialOrd + TimeUnitTrait,
impl<U> PartialOrd for DateTime<U>where
U: PartialOrd + TimeUnitTrait,
impl<U> Copy for DateTime<U>where
U: Copy + TimeUnitTrait,
impl<U> Eq for DateTime<U>where
U: Eq + TimeUnitTrait,
impl<U> Send for DateTime<U>where
U: TimeUnitTrait,
impl<U> StructuralPartialEq for DateTime<U>where
U: TimeUnitTrait,
impl<U> Sync for DateTime<U>where
U: TimeUnitTrait,
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)