Skip to main content

Timestamp

Struct Timestamp 

Source
pub struct Timestamp {
    pub seconds: i64,
    pub nanosecond: u32,
}
Expand description

An instant in time.

This is a well-known extension type (see ext) for points in time independent of a time zone, such as Unix timestamps. It holds the time since the Unix epoch (1970-01-01T00:00:00Z), ignoring leap seconds. The nanoseconds are always positive: -0.5 seconds are seconds: -1 and nanosecond: 500_000_000.

The fallback is the RFC 3339 representation in UTC as string. Instants outside of the years 0 to 9999 are written with an expanded year as in ISO 8601 (+10000-01-01T00:00:00Z).

use deser::ext::Timestamp;

let ts = Timestamp { seconds: 296638320, nanosecond: 0 };
assert_eq!(ts.to_string(), "1979-05-27T07:32:00Z");
assert_eq!("1979-05-27T00:32:00-07:00".parse::<Timestamp>().unwrap(), ts);

std::time::SystemTime serializes as Timestamp, as do the timestamp types of jiff, chrono and time with the respective features.

Fields§

§seconds: i64

The seconds since the Unix epoch.

§nanosecond: u32

The fraction of the second in nanoseconds (0 to 999_999_999).

Implementations§

Source§

impl Timestamp

Source

pub fn as_secs_f64(&self) -> f64

Returns the time since the epoch in seconds as float.

Source

pub fn to_datetime(&self) -> Option<Datetime>

Converts the timestamp into an offset date-time in UTC.

Returns None if the year is outside of 0 to 9999.

Trait Implementations§

Source§

impl Clone for Timestamp

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Timestamp

Source§

impl Debug for Timestamp

Source§

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

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

impl<'de> Deserialize<'de> for Timestamp

Source§

fn deserialize_into<'out>( out: &'out mut Option<Self>, state: &mut State, ) -> SinkHandle<'out, 'de>

Creates a sink that deserializes the value into the given slot. Read more
Source§

fn initial_value() -> Option<Self>

Provides the value of a missing struct field. Read more
Source§

fn deserialize_update<'out>( value: &'out mut Self, state: &mut State, ) -> SinkHandle<'out, 'de>

Creates a sink that updates an existing value. 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 Eq for Timestamp

Source§

impl Extension for Timestamp

Source§

fn name(&self) -> &str

Returns the human readable name of the extension type. Read more
Source§

fn fallback(&self) -> Atom<'_>

Lowers the value into the core data model. Read more
Source§

impl FromStr for Timestamp

Source§

fn from_str(s: &str) -> Result<Timestamp, Error>

Parses an offset date-time.

Years outside of 0 to 9999 can be given in the expanded representation of ISO 8601 (a sign and at least six digits).

Source§

type Err = Error

The associated error which can be returned from parsing.
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: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

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

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

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Timestamp

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Timestamp

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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(&self, _state: &mut State) -> Result<Chunk<'_>, Error>

Serializes this serializable.
Source§

fn finish(&self, _state: &mut State) -> Result<(), Error>

Invoked after the serialization finished. Read more
Source§

fn is_optional(&self) -> bool

Checks if the current value that would be serialized represents an optional value. Read more
Source§

fn describe(&self, d: &mut dyn Describe)

Describes the Rust shape of this value. Read more
Source§

fn container_shape(&self) -> ContainerShape

Returns the shape of this value if it’s a map or sequence. Read more
Source§

impl StructuralPartialEq for Timestamp

Source§

impl TryFrom<Datetime> for Timestamp

Source§

fn try_from(value: Datetime) -> Result<Timestamp, Error>

Converts an offset date-time into a timestamp.

Leap seconds are clamped to the previous second.

Source§

type Error = Error

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

impl TryFrom<Timestamp> for Datetime

Source§

fn try_from(value: Timestamp) -> Result<Datetime, Error>

Converts a timestamp into an offset date-time in UTC.

Source§

type Error = Error

The type returned in the event of a conversion error.

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> BorrowedExtension for T
where T: Extension,

Source§

type Value<'a> = T

The type of the values of this extension.
Source§

fn name(value: &T) -> &str

Returns the human readable name of the extension type. Read more
Source§

fn fallback<'v>(value: &'v T) -> Atom<'v>

Lowers the value into the core data model. Read more
Source§

fn to_static(value: &T) -> T

Detaches a value from the data it borrows. Read more
Source§

fn shorten<'s, 'l>(value: &'s T) -> &'s T
where 'l: 's,

Shortens the lifetime of a 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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.