pub struct DateTime { /* private fields */ }Expand description
A date and time value with nanosecond precision. Always in SVTC timezone.
Internally stored as nanoseconds since Unix epoch (1970-01-01T00:00:00Z). Only supports dates from 1970-01-01 onward.
Implementations§
Source§impl DateTime
impl DateTime
Sourcepub fn new(
year: i32,
month: u32,
day: u32,
hour: u32,
min: u32,
sec: u32,
nano: u32,
) -> Option<Self>
pub fn new( year: i32, month: u32, day: u32, hour: u32, min: u32, sec: u32, nano: u32, ) -> Option<Self>
Create from year, month, day, hour, minute, second, nanosecond. Returns None if the date is invalid or before Unix epoch.
pub fn from_ymd_hms( year: i32, month: u32, day: u32, hour: u32, min: u32, sec: u32, ) -> Result<Self, TypeError>
Sourcepub fn from_nanos(nanos: u64) -> Self
pub fn from_nanos(nanos: u64) -> Self
Create from a primary u64 nanoseconds value. Values beyond MAX_SAFE_NANOS are rejected to prevent downstream i32 overflow in date().
pub fn from_timestamp(timestamp: i64) -> Result<Self, TypeError>
pub fn from_timestamp_millis(millis: u64) -> Result<Self, TypeError>
pub fn from_timestamp_nanos(nanos: u128) -> Result<Self, TypeError>
pub fn timestamp(&self) -> i64
pub fn timestamp_millis(&self) -> i64
pub fn timestamp_nanos(&self) -> Result<i64, TypeError>
pub fn try_date(&self) -> Result<Date, TypeError>
pub fn date(&self) -> Date
pub fn time(&self) -> Time
Sourcepub fn to_nanos_since_epoch_u128(&self) -> u128
pub fn to_nanos_since_epoch_u128(&self) -> u128
Convert to nanoseconds since Unix epoch as u128.
pub fn year(&self) -> i32
pub fn month(&self) -> u32
pub fn day(&self) -> u32
pub fn hour(&self) -> u32
pub fn minute(&self) -> u32
pub fn second(&self) -> u32
pub fn nanosecond(&self) -> u32
Sourcepub fn add_duration(&self, dur: &Duration) -> Result<Self, TypeError>
pub fn add_duration(&self, dur: &Duration) -> Result<Self, TypeError>
Add a Duration to this DateTime, handling calendar arithmetic for months/days.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for DateTime
impl<'de> Deserialize<'de> for DateTime
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for DateTime
impl Ord for DateTime
Source§impl PartialOrd for DateTime
impl PartialOrd for DateTime
Source§impl TryFromValue for DateTime
impl TryFromValue for DateTime
Source§fn try_from_value(value: &Value) -> Result<Self, FromValueError>
fn try_from_value(value: &Value) -> Result<Self, FromValueError>
Attempt to extract a value of this type from a Value. Read more
impl Copy for DateTime
impl Eq for DateTime
impl IsDate for DateTime
impl IsTemporal for DateTime
impl IsTime for DateTime
impl StructuralPartialEq for DateTime
Auto Trait Implementations§
impl Freeze for DateTime
impl RefUnwindSafe for DateTime
impl Send for DateTime
impl Sync for DateTime
impl Unpin for DateTime
impl UnsafeUnpin for DateTime
impl UnwindSafe for DateTime
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
Mutably borrows from an owned value. Read more