#[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 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() -> DateTime<U>
pub const fn nat() -> DateTime<U>
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>) -> DateTime<U>
pub const fn from_opt_i64(v: Option<i64>) -> DateTime<U>
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<DateTime<Utc>>
👎Deprecated since 0.5.0: use as_cr instead
pub fn to_cr(&self) -> Option<DateTime<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<DateTime<Utc>>
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>
Source§impl Cast<DateTime<Microsecond>> for DateTime<Millisecond>
impl Cast<DateTime<Microsecond>> for DateTime<Millisecond>
Source§impl Cast<DateTime<Millisecond>> for DateTime<Nanosecond>
impl Cast<DateTime<Millisecond>> for DateTime<Nanosecond>
Source§impl Cast<DateTime<Millisecond>> for DateTime<Microsecond>
impl Cast<DateTime<Millisecond>> for DateTime<Microsecond>
Source§impl<U: TimeUnitTrait> Cast<DateTime<U>> for Option<bool>
Available on crate feature time only.
impl<U: TimeUnitTrait> Cast<DateTime<U>> for Option<bool>
time only.Source§impl<U: TimeUnitTrait> Cast<DateTime<U>> for Option<f32>
Available on crate feature time only.
impl<U: TimeUnitTrait> Cast<DateTime<U>> for Option<f32>
time only.Source§impl<U: TimeUnitTrait> Cast<DateTime<U>> for Option<f64>
Available on crate feature time only.
impl<U: TimeUnitTrait> Cast<DateTime<U>> for Option<f64>
time only.Source§impl<U: TimeUnitTrait> Cast<DateTime<U>> for Option<i32>
Available on crate feature time only.
impl<U: TimeUnitTrait> Cast<DateTime<U>> for Option<i32>
time only.Source§impl<U: TimeUnitTrait> Cast<DateTime<U>> for Option<i64>
Available on crate feature time only.
impl<U: TimeUnitTrait> Cast<DateTime<U>> for Option<i64>
time only.Source§impl<U: TimeUnitTrait> Cast<DateTime<U>> for Option<isize>
Available on crate feature time only.
impl<U: TimeUnitTrait> Cast<DateTime<U>> for Option<isize>
time only.Source§impl<U: TimeUnitTrait> Cast<DateTime<U>> for Option<u64>
Available on crate feature time only.
impl<U: TimeUnitTrait> Cast<DateTime<U>> for Option<u64>
time only.Source§impl<U: TimeUnitTrait> Cast<DateTime<U>> for Option<usize>
Available on crate feature time only.
impl<U: TimeUnitTrait> Cast<DateTime<U>> for Option<usize>
time only.Source§impl<U: TimeUnitTrait> Cast<Option<i64>> for DateTime<U>
Available on crate feature time only.
impl<U: TimeUnitTrait> Cast<Option<i64>> for DateTime<U>
time only.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>
Available on crate feature time only.
impl<U: TimeUnitTrait> GetDataType for DateTime<U>
time only.Source§impl<Unit: TimeUnitTrait> IsNone for DateTime<Unit>
Available on crate feature time only.
impl<Unit: TimeUnitTrait> IsNone for DateTime<Unit>
time only.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§fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self::Inner: PartialOrd,
fn sort_cmp(&self, other: &Self) -> Orderingwhere
Self::Inner: PartialOrd,
None as the largest value. Read moreSource§fn sort_cmp_rev(&self, other: &Self) -> Orderingwhere
Self::Inner: PartialOrd,
fn sort_cmp_rev(&self, other: &Self) -> Orderingwhere
Self::Inner: PartialOrd,
None as the largest value. Read more