pub struct UnixNanos(/* private fields */);Expand description
Represents a timestamp in nanoseconds since the UNIX epoch.
Implementations§
Source§impl UnixNanos
impl UnixNanos
Sourcepub const fn as_seconds(&self) -> u64
pub const fn as_seconds(&self) -> u64
Returns the timestamp as seconds, truncating sub-second precision.
Sourcepub const fn as_millis(&self) -> u64
pub const fn as_millis(&self) -> u64
Returns the timestamp as milliseconds, truncating sub-millisecond precision.
Sourcepub const fn as_micros(&self) -> u64
pub const fn as_micros(&self) -> u64
Returns the timestamp as microseconds, truncating sub-microsecond precision.
Sourcepub const fn from_seconds(seconds: u64) -> Self
pub const fn from_seconds(seconds: u64) -> Self
Sourcepub const fn from_millis(millis: u64) -> Self
pub const fn from_millis(millis: u64) -> Self
Sourcepub const fn from_millis_checked(millis: i64) -> Option<Self>
pub const fn from_millis_checked(millis: i64) -> Option<Self>
Creates a new UnixNanos from a signed millisecond timestamp.
Returns None if millis is negative or the result overflows u64.
Sourcepub const fn from_micros(micros: u64) -> Self
pub const fn from_micros(micros: u64) -> Self
Sourcepub const fn from_micros_checked(micros: i64) -> Option<Self>
pub const fn from_micros_checked(micros: i64) -> Option<Self>
Creates a new UnixNanos from a signed microsecond timestamp.
Returns None if micros is negative or the result overflows u64.
Sourcepub const fn as_i64(&self) -> i64
pub const fn as_i64(&self) -> i64
Returns the underlying value as i64.
§Panics
Panics if the value exceeds i64::MAX (approximately year 2262).
Sourcepub fn to_datetime_utc(&self) -> Timestamp
pub fn to_datetime_utc(&self) -> Timestamp
Converts the underlying value to a datetime (UTC).
§Panics
Panics if Jiff’s supported timestamp range no longer includes all u64 nanosecond values.
Sourcepub fn to_rfc3339(&self) -> String
pub fn to_rfc3339(&self) -> String
Converts the underlying value to an ISO 8601 (RFC 3339) string.
Sourcepub const fn duration_since(&self, other: &Self) -> Option<DurationNanos>
pub const fn duration_since(&self, other: &Self) -> Option<DurationNanos>
Calculates the duration in nanoseconds since another UnixNanos instance.
Returns Some(duration) if self is later than other, otherwise None if other is
greater than self (indicating a negative duration is not possible with DurationNanos).
Sourcepub const fn saturating_duration_since(&self, earlier: Self) -> DurationNanos
pub const fn saturating_duration_since(&self, earlier: Self) -> DurationNanos
Calculates the duration in nanoseconds since earlier, saturating at zero.
Sourcepub const fn floor(self, interval: DurationNanos) -> Self
pub const fn floor(self, interval: DurationNanos) -> Self
Rounds this timestamp down to the nearest multiple of interval since the UNIX epoch.
§Panics
Panics if interval is zero.
Sourcepub const fn checked_add(self, rhs: DurationNanos) -> Option<Self>
pub const fn checked_add(self, rhs: DurationNanos) -> Option<Self>
Returns Some(self + rhs) or None if the addition would overflow
Sourcepub const fn checked_sub(self, rhs: DurationNanos) -> Option<Self>
pub const fn checked_sub(self, rhs: DurationNanos) -> Option<Self>
Returns Some(self - rhs) or None if the subtraction would underflow
Sourcepub const fn saturating_add(self, rhs: DurationNanos) -> Self
pub const fn saturating_add(self, rhs: DurationNanos) -> Self
Adds rhs, saturating at UnixNanos::max.
Sourcepub const fn saturating_sub(self, rhs: DurationNanos) -> Self
pub const fn saturating_sub(self, rhs: DurationNanos) -> Self
Subtracts rhs, saturating at zero.
Trait Implementations§
Source§impl Add<DurationNanos> for UnixNanos
Adds a duration to a timestamp.
impl Add<DurationNanos> for UnixNanos
Adds a duration to a timestamp.
§Panics
Panics on overflow. Use UnixNanos::checked_add or UnixNanos::saturating_add for
explicit overflow handling.
Source§impl AddAssign<DurationNanos> for UnixNanos
Add-assigns a duration to UnixNanos.
impl AddAssign<DurationNanos> for UnixNanos
Add-assigns a duration to UnixNanos.
§Panics
Panics on overflow. This is intentional fail-fast behavior for timestamp arithmetic.
Source§fn add_assign(&mut self, rhs: DurationNanos)
fn add_assign(&mut self, rhs: DurationNanos)
+= operation. Read moreimpl Copy for UnixNanos
Source§impl<'de> Deserialize<'de> for UnixNanos
impl<'de> Deserialize<'de> for UnixNanos
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>,
impl Eq for UnixNanos
Source§impl From<&str> for UnixNanos
Converts a string slice to UnixNanos.
impl From<&str> for UnixNanos
Converts a string slice to UnixNanos.
§Panics
This implementation will panic if the string cannot be parsed into a valid UnixNanos.
This is intentional fail-fast behavior where invalid timestamps indicate a critical
logic error that should halt execution rather than silently propagate incorrect data.
For error handling without panicking, use str::parse::<UnixNanos>() which returns
a Result.
Source§impl From<String> for UnixNanos
impl From<String> for UnixNanos
§Panics
This implementation will panic if the string cannot be parsed into a valid UnixNanos.
This is intentional fail-fast behavior where invalid timestamps indicate a critical
logic error that should halt execution rather than silently propagate incorrect data.
For error handling without panicking, use str::parse::<UnixNanos>() which returns
a Result.
Source§impl From<SystemTime> for UnixNanos
impl From<SystemTime> for UnixNanos
Source§fn from(value: SystemTime) -> Self
fn from(value: SystemTime) -> Self
Source§impl Ord for UnixNanos
impl Ord for UnixNanos
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for UnixNanos
impl PartialOrd for UnixNanos
Source§impl PartialOrd<Option<u64>> for UnixNanos
impl PartialOrd<Option<u64>> for UnixNanos
Source§impl PartialOrd<UnixNanos> for u64
impl PartialOrd<UnixNanos> for u64
Source§impl PartialOrd<u64> for UnixNanos
impl PartialOrd<u64> for UnixNanos
impl StructuralPartialEq for UnixNanos
Source§impl Sub for UnixNanos
Returns the elapsed duration between two timestamps.
impl Sub for UnixNanos
Returns the elapsed duration between two timestamps.
§Panics
Panics if rhs is later than self. Use UnixNanos::duration_since or
UnixNanos::saturating_duration_since when the timestamps may be out of order.
Source§impl Sub<DurationNanos> for UnixNanos
Subtracts a duration from a timestamp.
impl Sub<DurationNanos> for UnixNanos
Subtracts a duration from a timestamp.
§Panics
Panics on underflow. Use UnixNanos::checked_sub or UnixNanos::saturating_sub for
explicit underflow handling.
Source§impl SubAssign<DurationNanos> for UnixNanos
Sub-assigns a duration from UnixNanos.
impl SubAssign<DurationNanos> for UnixNanos
Sub-assigns a duration from UnixNanos.
§Panics
Panics on underflow. This is intentional fail-fast behavior for timestamp arithmetic.
Source§fn sub_assign(&mut self, rhs: DurationNanos)
fn sub_assign(&mut self, rhs: DurationNanos)
-= operation. Read moreAuto Trait Implementations§
impl Freeze for UnixNanos
impl RefUnwindSafe for UnixNanos
impl Send for UnixNanos
impl Sync for UnixNanos
impl Unpin for UnixNanos
impl UnsafeUnpin for UnixNanos
impl UnwindSafe for UnixNanos
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.