Struct Timestamp

Source
pub struct Timestamp(/* private fields */);
Expand description

A Unix timestamp with nanosecond precision.

Implementations§

Source§

impl Timestamp

Source

pub const MIN: Self

The minimum timestamp, 1970-01-01T00:00:00Z.

Source

pub const MAX: Self

The maximum timestamp, 9999-12-31T23:59:59.999999999Z.

Source

pub fn from_unix(unix_time: Duration) -> Option<Self>

Try create a timestamp from time since the Unix epoch.

If the unix_time is within Timestamp::MIN..=Timestamp::MAX then this method will return Some. Otherwise it will return None.

Source

pub fn to_unix(&self) -> Duration

Get the value of the timestamp as time since the Unix epoch.

Source

pub fn try_from_str(ts: &str) -> Result<Self, ParseTimestampError>

Try parse a timestamp from an RFC3339 formatted representation.

Source

pub fn parse(ts: impl Display) -> Result<Self, ParseTimestampError>

Try parse a timestamp from an RFC3339 formatted value.

Source

pub fn duration_since(self, earlier: Self) -> Option<Duration>

Calculate the timespan between two timestamps.

This method will return None if earlier is actually after self.

Source

pub fn to_system_time(&self) -> SystemTime

Convert the timestamp into a system timestamp.

This method can be used for interoperability with code expecting a standard library timestamp.

Source

pub fn from_parts(parts: Parts) -> Option<Self>

Try get a timestamp from its individual date and time parts.

If the resulting timestamp is within Timestamp::MIN..=Timestamp::MAX then this method will return Some. Otherwise it will return None.

If any field of parts would overflow its maximum value, such as days: 32, then it will wrap into the next unit.

Source

pub fn to_parts(&self) -> Parts

Get the individual date and time parts of the timestamp.

The returned parts are in exactly the form needed to display them. Months and days are both one-based.

Source

pub fn checked_add(&self, rhs: Duration) -> Option<Self>

Add a duration to this timestamp.

If the result would be greater than Timestamp::MAX then None is returned.

Source

pub fn checked_sub(&self, rhs: Duration) -> Option<Self>

Subtract a duration to this timestamp.

If the result would be less than Timestamp::MIN then None is returned.

Source

pub fn checked_duration_since(&self, earlier: Timestamp) -> Option<Duration>

Get the duration between this timestamp and an earlier one.

Trait Implementations§

Source§

impl Add<Duration> for Timestamp

Source§

type Output = Timestamp

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Duration) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign<Duration> for Timestamp

Source§

fn add_assign(&mut self, rhs: Duration)

Performs the += operation. Read more
Source§

impl Clone for Timestamp

Source§

fn clone(&self) -> Timestamp

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Timestamp

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Timestamp

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for Timestamp

Source§

type Err = ParseTimestampError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<'v> FromValue<'v> for Timestamp

Source§

fn from_value(value: Value<'v>) -> Option<Self>

Perform the conversion.
Source§

impl Hash for Timestamp

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Timestamp

Source§

fn cmp(&self, other: &Timestamp) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'a> PartialEq<&'a Timestamp> for Timestamp

Source§

fn eq(&self, other: &&'a Timestamp) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialEq<Timestamp> for &'a Timestamp

Source§

fn eq(&self, other: &Timestamp) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for Timestamp

Source§

fn eq(&self, other: &Timestamp) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Timestamp

Source§

fn partial_cmp(&self, other: &Timestamp) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Timestamp

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub<Duration> for Timestamp

Source§

type Output = Timestamp

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Duration) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub for Timestamp

Source§

type Output = Duration

The resulting type after applying the - operator.
Source§

fn sub(self, earlier: Timestamp) -> Self::Output

Performs the - operation. Read more
Source§

impl SubAssign<Duration> for Timestamp

Source§

fn sub_assign(&mut self, rhs: Duration)

Performs the -= operation. Read more
Source§

impl ToExtent for Timestamp

Source§

fn to_extent(&self) -> Option<Extent>

Perform the conversion.
Source§

impl ToValue for Timestamp

Source§

fn to_value(&self) -> Value<'_>

Perform the conversion.
Source§

impl Value for Timestamp

Source§

fn stream<'sval, S: Stream<'sval> + ?Sized>( &'sval self, stream: &mut S, ) -> Result

Stream this value through a Stream.
Source§

fn tag(&self) -> Option<Tag>

Get the tag of this value, if there is one.
Source§

fn to_bool(&self) -> Option<bool>

Try convert this value into a boolean.
Source§

fn to_f32(&self) -> Option<f32>

Try convert this value into a 32bit binary floating point number.
Source§

fn to_f64(&self) -> Option<f64>

Try convert this value into a 64bit binary floating point number.
Source§

fn to_i8(&self) -> Option<i8>

Try convert this value into a signed 8bit integer.
Source§

fn to_i16(&self) -> Option<i16>

Try convert this value into a signed 16bit integer.
Source§

fn to_i32(&self) -> Option<i32>

Try convert this value into a signed 32bit integer.
Source§

fn to_i64(&self) -> Option<i64>

Try convert this value into a signed 64bit integer.
Source§

fn to_i128(&self) -> Option<i128>

Try convert this value into a signed 128bit integer.
Source§

fn to_u8(&self) -> Option<u8>

Try convert this value into an unsigned 8bit integer.
Source§

fn to_u16(&self) -> Option<u16>

Try convert this value into an unsigned 16bit integer.
Source§

fn to_u32(&self) -> Option<u32>

Try convert this value into an unsigned 32bit integer.
Source§

fn to_u64(&self) -> Option<u64>

Try convert this value into an unsigned 64bit integer.
Source§

fn to_u128(&self) -> Option<u128>

Try convert this value into an unsigned 128bit integer.
Source§

fn to_text(&self) -> Option<&str>

Try convert this value into a text string.
Source§

fn to_binary(&self) -> Option<&[u8]>

Try convert this value into a bitstring.
Source§

impl Copy for Timestamp

Source§

impl Eq for Timestamp

Source§

impl StructuralPartialEq for Timestamp

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Value for T
where T: Value,