#[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) -> Self
pub fn duration_trunc(self, duration: TimeDelta) -> Self
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.