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 from_unix_timestamp(seconds: i64) -> Self

👎Deprecated: Use Timestamp::UNIX_EPOCH.checked_add(Duration::seconds(seconds))
Deprecated

Use Timestamp::UNIX_EPOCH.checked_add(Duration::seconds(seconds))

source

pub fn from_unix_timestamp_ms(milliseconds: i64) -> Self

👎Deprecated: Use Timestamp::UNIX_EPOCH.checked_add(Duration::milliseconds(milliseconds))
Deprecated

Use Timestamp::UNIX_EPOCH.checked_add(Duration::milliseconds(milliseconds))

source

pub fn to_unix_timestamp_ms(self) -> i64

👎Deprecated: Use self.duration_since(Timestamp::UNIX_EPOCH).whole_milliseconds()
Deprecated

Use self.duration_since(Timestamp::UNIX_EPOCH).whole_milliseconds()

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

§

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

source§

fn clone(&self) -> Timestamp

Returns a copy 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

§

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<'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 + Send + Sync>>

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 + Send + Sync>>

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 + PartialOrd,

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

impl PartialEq for Timestamp

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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

This method 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

This method 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

This method 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

This method 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

§

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 StructuralEq 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> DynClone for T
where T: Clone,

source§

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

§

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

§

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<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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§

default 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>,

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

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>,