Struct Timestamp

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

UTC Timestamp with nanosecond precision, millisecond-precision when serialized to serde (JSON).

A Deref/DerefMut implementation is provided to gain access to the inner PrimitiveDateTime object.

Implementations§

Source§

impl Timestamp

Source

pub fn to_calendar_date(&self) -> (i32, Month, u8)

Get the year, month, and day.

Like PrimitiveDateTime::to_calendar_date, but optimized for SSE2/AVX2 when available.

assert_eq!(
    Timestamp::from(datetime!(2019-01-01 0:00)).to_calendar_date(),
    (2019, Month::January, 1)
);
Source§

impl Timestamp

Source

pub fn now_utc() -> Self

Get the current time, assuming UTC.

Source§

impl Timestamp

Source

pub const UNIX_EPOCH: Self

Unix Epoch – 1970-01-01 Midnight

Source

pub const fn from_primitive_datetime(dt: PrimitiveDateTime) -> Self

Constructs a Timestamp from a PrimitiveDateTime

Source

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

Returns the amount of time elapsed from an earlier point in time.

Source

pub fn format_raw<F: Bit, O: Bit, P: Unsigned>( &self, offset: UtcOffset, ) -> TimestampStr<FormatString<F, O, P>>
where FormatString<F, O, P>: IsValidFormat,

Formats the timestamp given the provided formatting parameters

Source

pub fn format_with_precision<P: Unsigned>( &self, ) -> TimestampStr<FormatString<True, False, P>>
where FormatString<True, False, P>: IsValidFormat,

Formats a full timestamp without offset, using the given subsecond precision level.

Source

pub fn format(&self) -> TimestampStr<FullMilliseconds>

Format timestamp to ISO8601 with full punctuation, to millisecond precision.

Source

pub fn format_nanoseconds(&self) -> TimestampStr<FullNanoseconds>

Format timestamp to ISO8601 with extended precision to nanoseconds.

Source

pub fn format_microseconds(&self) -> TimestampStr<FullMicroseconds>

Format timestamp to ISO8601 with extended precision to microseconds.

Source

pub fn format_short(&self) -> TimestampStr<ShortMilliseconds>

Format timestamp to ISO8601 without most punctuation, to millisecond precision.

Source

pub fn format_with_offset( &self, offset: UtcOffset, ) -> TimestampStr<FullMillisecondsOffset>

Format timestamp to ISO8601 with arbitrary UTC offset. Any offset is formatted as +HH:MM, and no timezone conversions are done. It is interpreted literally.

Source

pub fn format_with_offset_and_precision<P: Unsigned>( &self, offset: UtcOffset, ) -> TimestampStr<FormatString<True, True, P>>
where FormatString<True, True, P>: IsValidFormat,

Formats a full timestamp with timezone offset, and the provided level of subsecond precision.

Source

pub fn parse(ts: &str) -> Option<Self>

Parse to UTC timestamp from any ISO8601 string. Offsets are applied during parsing.

Source

pub const fn assume_offset(self, offset: UtcOffset) -> OffsetDateTime

Convert to time::OffsetDateTime with the given offset.

Source

pub const fn checked_add(self, duration: Duration) -> Option<Self>

Computes self + duration, returning None if an overflow occurred.

See PrimitiveDateTime::checked_add for more implementation details

Source

pub const fn checked_sub(self, duration: Duration) -> Option<Self>

Computes self - duration, returning None if an overflow occurred.

See PrimitiveDateTime::checked_sub for more implementation details

Source

pub const fn saturating_add(self, duration: Duration) -> Self

Computes self + duration, saturating value on overflow.

See PrimitiveDateTime::saturating_add for more implementation details

Source

pub const fn saturating_sub(self, duration: Duration) -> Self

Computes self - duration, saturating value on overflow.

See PrimitiveDateTime::saturating_sub for more implementation details

Methods from Deref<Target = PrimitiveDateTime>§

Trait Implementations§

Source§

impl<T> Add<T> for Timestamp

Source§

type Output = Timestamp

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T> AddAssign<T> for Timestamp

Source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
Source§

impl Arbitrary for Timestamp

Source§

fn arbitrary(g: &mut Gen) -> Self

Return an arbitrary value. Read more
Source§

fn shrink(&self) -> Box<dyn Iterator<Item = Self>>

Return an iterator of values that are smaller than itself. Read more
Source§

impl BorshDeserialize for Timestamp

Source§

fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self>

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

Source§

impl BorshSerialize for Timestamp

Source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<()>

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 Deref for Timestamp

Source§

type Target = PrimitiveDateTime

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Timestamp

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

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

Source§

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 Display for Timestamp

Source§

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

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

impl Distribution<Timestamp> for Standard

Source§

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Timestamp

Generate a random value of T, using rng as the source of randomness.
Source§

fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
Source§

fn map<F, S>(self, func: F) -> DistMap<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Create a distribution of values of ‘S’ by mapping the output of Self through the closure F Read more
Source§

impl From<OffsetDateTime> for Timestamp

Source§

fn from(ts: OffsetDateTime) -> Self

Converts to this type from the input type.
Source§

impl From<PrimitiveDateTime> for Timestamp

Source§

fn from(ts: PrimitiveDateTime) -> Self

Converts to this type from the input type.
Source§

impl From<SystemTime> for Timestamp

Source§

fn from(ts: SystemTime) -> Self

Converts to this type from the input type.
Source§

impl From<Timestamp> for SystemTime

Source§

fn from(ts: Timestamp) -> Self

Converts to this type from the input type.
Source§

impl<'a> FromSql<'a> for Timestamp

Source§

fn from_sql( ty: &Type, raw: &'a [u8], ) -> Result<Self, Box<dyn Error + Sync + Send>>

Creates a new value of this type from a buffer of data of the specified Postgres Type in its binary format. Read more
Source§

fn accepts(ty: &Type) -> bool

Determines if a value of this type can be created from the specified Postgres Type.
Source§

fn from_sql_null(ty: &Type) -> Result<Self, Box<dyn Error + Sync + Send>>

Creates a new value of this type from a NULL SQL value. Read more
Source§

fn from_sql_nullable( ty: &Type, raw: Option<&'a [u8]>, ) -> Result<Self, Box<dyn Error + Sync + Send>>

A convenience function that delegates to from_sql and from_sql_null depending on the value of raw.
Source§

impl FromSql for Timestamp

Source§

fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self>

Converts SQLite value into Rust value.
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 JsonSchema for Timestamp

Source§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
Source§

fn json_schema(_gen: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. 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 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>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

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

impl<T> Sub<T> for Timestamp

Source§

type Output = Timestamp

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T> SubAssign<T> for Timestamp

Source§

fn sub_assign(&mut self, rhs: T)

Performs the -= operation. Read more
Source§

impl ToSql for Timestamp

Source§

fn to_sql( &self, ty: &Type, out: &mut BytesMut, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
where Self: Sized,

Converts the value of self into the binary format of the specified Postgres Type, appending it to out. Read more
Source§

fn accepts(ty: &Type) -> bool

Determines if a value of this type can be converted to the specified Postgres Type.
Source§

fn to_sql_checked( &self, ty: &Type, out: &mut BytesMut, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>

An adaptor method used internally by Rust-Postgres. Read more
Source§

fn encode_format(&self, _ty: &Type) -> Format

Specify the encode format
Source§

impl ToSql for Timestamp

Source§

fn to_sql(&self) -> Result<ToSqlOutput<'_>>

Converts Rust value to SQLite value
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> BorrowToSql for T
where T: ToSql,

Source§

fn borrow_to_sql(&self) -> &dyn ToSql

Returns a reference to self as a ToSql trait object.
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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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<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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

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

Source§

impl<T> FromSqlOwned for T
where T: for<'a> FromSql<'a>,