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
impl Timestamp
Sourcepub fn to_calendar_date(&self) -> (i32, Month, u8)
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
impl Timestamp
Sourcepub const UNIX_EPOCH: Self
pub const UNIX_EPOCH: Self
Unix Epoch – 1970-01-01 Midnight
Sourcepub const fn from_primitive_datetime(dt: PrimitiveDateTime) -> Self
pub const fn from_primitive_datetime(dt: PrimitiveDateTime) -> Self
Constructs a Timestamp
from a PrimitiveDateTime
Sourcepub fn duration_since(self, earlier: Self) -> Duration
pub fn duration_since(self, earlier: Self) -> Duration
Returns the amount of time elapsed from an earlier point in time.
Sourcepub fn format_raw<F: Bit, O: Bit, P: Unsigned>(
&self,
offset: UtcOffset,
) -> TimestampStr<FormatString<F, O, P>>where
FormatString<F, O, P>: IsValidFormat,
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
Sourcepub fn format_with_precision<P: Unsigned>(
&self,
) -> TimestampStr<FormatString<True, False, P>>
pub fn format_with_precision<P: Unsigned>( &self, ) -> TimestampStr<FormatString<True, False, P>>
Formats a full timestamp without offset, using the given subsecond precision level.
Sourcepub fn format(&self) -> TimestampStr<FullMilliseconds>
pub fn format(&self) -> TimestampStr<FullMilliseconds>
Format timestamp to ISO8601 with full punctuation, to millisecond precision.
Sourcepub fn format_nanoseconds(&self) -> TimestampStr<FullNanoseconds>
pub fn format_nanoseconds(&self) -> TimestampStr<FullNanoseconds>
Format timestamp to ISO8601 with extended precision to nanoseconds.
Sourcepub fn format_microseconds(&self) -> TimestampStr<FullMicroseconds>
pub fn format_microseconds(&self) -> TimestampStr<FullMicroseconds>
Format timestamp to ISO8601 with extended precision to microseconds.
Sourcepub fn format_short(&self) -> TimestampStr<ShortMilliseconds>
pub fn format_short(&self) -> TimestampStr<ShortMilliseconds>
Format timestamp to ISO8601 without most punctuation, to millisecond precision.
Sourcepub fn format_with_offset(
&self,
offset: UtcOffset,
) -> TimestampStr<FullMillisecondsOffset>
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.
Sourcepub fn format_with_offset_and_precision<P: Unsigned>(
&self,
offset: UtcOffset,
) -> TimestampStr<FormatString<True, True, P>>
pub fn format_with_offset_and_precision<P: Unsigned>( &self, offset: UtcOffset, ) -> TimestampStr<FormatString<True, True, P>>
Formats a full timestamp with timezone offset, and the provided level of subsecond precision.
Sourcepub fn parse(ts: &str) -> Option<Self>
pub fn parse(ts: &str) -> Option<Self>
Parse to UTC timestamp from any ISO8601 string. Offsets are applied during parsing.
Sourcepub const fn assume_offset(self, offset: UtcOffset) -> OffsetDateTime
pub const fn assume_offset(self, offset: UtcOffset) -> OffsetDateTime
Convert to time::OffsetDateTime
with the given offset.
Sourcepub const fn checked_add(self, duration: Duration) -> Option<Self>
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
Sourcepub const fn checked_sub(self, duration: Duration) -> Option<Self>
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
Sourcepub const fn saturating_add(self, duration: Duration) -> Self
pub const fn saturating_add(self, duration: Duration) -> Self
Computes self + duration
, saturating value on overflow.
See PrimitiveDateTime::saturating_add
for more implementation details
Sourcepub const fn saturating_sub(self, duration: Duration) -> Self
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>§
pub const MIN: PrimitiveDateTime
pub const MAX: PrimitiveDateTime
Trait Implementations§
Source§impl<T> AddAssign<T> for Timestampwhere
PrimitiveDateTime: AddAssign<T>,
impl<T> AddAssign<T> for Timestampwhere
PrimitiveDateTime: AddAssign<T>,
Source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+=
operation. Read moreSource§impl BorshDeserialize for Timestamp
impl BorshDeserialize for Timestamp
fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self>
Source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl BorshSerialize for Timestamp
impl BorshSerialize for Timestamp
Source§impl<'de> Deserialize<'de> for Timestamp
impl<'de> Deserialize<'de> for Timestamp
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>,
Source§impl Distribution<Timestamp> for Standard
impl Distribution<Timestamp> for Standard
Source§impl From<OffsetDateTime> for Timestamp
impl From<OffsetDateTime> for Timestamp
Source§fn from(ts: OffsetDateTime) -> Self
fn from(ts: OffsetDateTime) -> Self
Source§impl From<PrimitiveDateTime> for Timestamp
impl From<PrimitiveDateTime> for Timestamp
Source§fn from(ts: PrimitiveDateTime) -> Self
fn from(ts: PrimitiveDateTime) -> Self
Source§impl From<SystemTime> for Timestamp
impl From<SystemTime> for Timestamp
Source§fn from(ts: SystemTime) -> Self
fn from(ts: SystemTime) -> Self
Source§impl From<Timestamp> for SystemTime
impl From<Timestamp> for SystemTime
Source§impl<'a> FromSql<'a> for Timestamp
impl<'a> FromSql<'a> for Timestamp
Source§fn from_sql(
ty: &Type,
raw: &'a [u8],
) -> Result<Self, Box<dyn Error + Sync + Send>>
fn from_sql( ty: &Type, raw: &'a [u8], ) -> Result<Self, Box<dyn Error + Sync + Send>>
Type
in its binary format. Read moreSource§fn accepts(ty: &Type) -> bool
fn accepts(ty: &Type) -> bool
Type
.Source§impl FromSql for Timestamp
impl FromSql for Timestamp
Source§fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self>
fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self>
Source§impl JsonSchema for Timestamp
impl JsonSchema for Timestamp
Source§fn schema_name() -> String
fn schema_name() -> String
Source§fn json_schema(_gen: &mut SchemaGenerator) -> Schema
fn json_schema(_gen: &mut SchemaGenerator) -> Schema
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moreSource§impl Ord for Timestamp
impl Ord for Timestamp
Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
Source§impl<T> SubAssign<T> for Timestampwhere
PrimitiveDateTime: SubAssign<T>,
impl<T> SubAssign<T> for Timestampwhere
PrimitiveDateTime: SubAssign<T>,
Source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-=
operation. Read moreSource§impl ToSql for Timestamp
impl ToSql for Timestamp
Source§fn to_sql(
&self,
ty: &Type,
out: &mut BytesMut,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>where
Self: Sized,
fn to_sql(
&self,
ty: &Type,
out: &mut BytesMut,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>where
Self: Sized,
self
into the binary format of the specified
Postgres Type
, appending it to out
. Read moreSource§fn accepts(ty: &Type) -> bool
fn accepts(ty: &Type) -> bool
Type
.Source§fn to_sql_checked(
&self,
ty: &Type,
out: &mut BytesMut,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn to_sql_checked( &self, ty: &Type, out: &mut BytesMut, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§fn encode_format(&self, _ty: &Type) -> Format
fn encode_format(&self, _ty: &Type) -> Format
Source§impl ToSql for Timestamp
impl ToSql for Timestamp
Source§fn to_sql(&self) -> Result<ToSqlOutput<'_>>
fn to_sql(&self) -> Result<ToSqlOutput<'_>>
impl Copy for Timestamp
impl Eq for Timestamp
impl StructuralPartialEq for Timestamp
Auto Trait Implementations§
impl Freeze for Timestamp
impl RefUnwindSafe for Timestamp
impl Send for Timestamp
impl Sync for Timestamp
impl Unpin for Timestamp
impl UnwindSafe for Timestamp
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
Source§impl<T> BorrowToSql for Twhere
T: ToSql,
impl<T> BorrowToSql for Twhere
T: ToSql,
Source§fn borrow_to_sql(&self) -> &dyn ToSql
fn borrow_to_sql(&self) -> &dyn ToSql
self
as a ToSql
trait object.