pub struct Timestamp(/* private fields */);Expand description
A safe wrapper around Postgres TIMESTAMP WITHOUT TIME ZONE type, backed by a pg_sys::Timestamp integer value.
Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub fn new(
year: i32,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: f64,
) -> Result<Timestamp, DateTimeConversionError>
pub fn new( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: f64, ) -> Result<Timestamp, DateTimeConversionError>
Construct a new Timestamp from its constituent parts.
§Errors
Returns a DateTimeConversionError if any part is outside the bounds for that part
Sourcepub fn new_unchecked(
year: isize,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: f64,
) -> Timestamp
pub fn new_unchecked( year: isize, month: u8, day: u8, hour: u8, minute: u8, second: f64, ) -> Timestamp
Sourcepub fn positive_infinity() -> Timestamp
pub fn positive_infinity() -> Timestamp
Construct a new Timestamp representing positive infinity
Sourcepub fn negative_infinity() -> Timestamp
pub fn negative_infinity() -> Timestamp
Construct a new Timestamp representing negative infinity
Sourcepub fn is_infinity(&self) -> bool
pub fn is_infinity(&self) -> bool
Does this Timestamp represent positive infinity?
Sourcepub fn is_neg_infinity(&self) -> bool
pub fn is_neg_infinity(&self) -> bool
Does this Timestamp represent negative infinity?
Sourcepub fn microseconds(&self) -> u32
pub fn microseconds(&self) -> u32
Return the microseconds part. This is not the time counted in microseconds, but the
fractional seconds
Sourcepub fn to_hms_micro(&self) -> (u8, u8, u8, u32)
pub fn to_hms_micro(&self) -> (u8, u8, u8, u32)
Return the hour, minute, second, and microseconds as a Rust tuple
pub fn is_finite(&self) -> bool
Sourcepub fn truncate(self, units: DateTimeParts) -> Timestamp
pub fn truncate(self, units: DateTimeParts) -> Timestamp
Truncate Timestamp to specified units
Sourcepub fn age(&self, other: &Timestamp) -> Interval
pub fn age(&self, other: &Timestamp) -> Interval
Subtract other from self, producing a “symbolic” result that uses years and months, rather than just days
Sourcepub fn into_inner(self) -> i64
pub fn into_inner(self) -> i64
Return the backing pg_sys::Timestamp value.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Timestamp
impl<'de> Deserialize<'de> for Timestamp
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Timestamp, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Timestamp, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl From<Timestamp> for TimestampWithTimeZone
impl From<Timestamp> for TimestampWithTimeZone
Source§fn from(value: Timestamp) -> TimestampWithTimeZone
fn from(value: Timestamp) -> TimestampWithTimeZone
Source§impl From<TimestampWithTimeZone> for Timestamp
impl From<TimestampWithTimeZone> for Timestamp
Source§fn from(value: TimestampWithTimeZone) -> Timestamp
fn from(value: TimestampWithTimeZone) -> Timestamp
Source§impl From<i64> for Timestamp
Create a Timestamp from a pg_sys::Timestamp
impl From<i64> for Timestamp
Create a Timestamp from a pg_sys::Timestamp
Note that pg_sys::Timestamp is an i64 as a microsecond offset from the “Postgres epoch”.
This impl currently allows producing a Timestamp that cannot be constructed by SQL,
such as a timestamp before “Julian day zero”.
The details of the encoding may also prove surprising, for instance:
- Postgres uses Julian days to reason about time instead of the Gregorian calendar
- There is no “year zero”, so Postgres defines the offset of -2000 years as 1 BC instead
- Some values such as
i64::MINandi64::MAXhave special meanings as infinities - The way
Timestamptranslates to/fromTimestampWithTimeZone, or rather doesn’t, is “fun” - In the past
pg_sys::Timestamp’s type has changed, so in the future this may change with it - This is likely to coincide with a change in Timestamp’s precision
Source§impl FromDatum for Timestamp
impl FromDatum for Timestamp
Source§unsafe fn from_polymorphic_datum(
datum: Datum,
is_null: bool,
_: Oid,
) -> Option<Timestamp>
unsafe fn from_polymorphic_datum( datum: Datum, is_null: bool, _: Oid, ) -> Option<Timestamp>
from_datum for instantiating polymorphic types
which require preserving the dynamic type metadata. Read moreSource§const GET_TYPOID: bool = false
const GET_TYPOID: bool = false
from_datum?Source§unsafe fn from_datum(datum: Datum, is_null: bool) -> Option<Self>where
Self: Sized,
unsafe fn from_datum(datum: Datum, is_null: bool) -> Option<Self>where
Self: Sized,
Source§unsafe fn from_datum_in_memory_context(
memory_context: PgMemoryContexts,
datum: Datum,
is_null: bool,
typoid: Oid,
) -> Option<Self>where
Self: Sized,
unsafe fn from_datum_in_memory_context(
memory_context: PgMemoryContexts,
datum: Datum,
is_null: bool,
typoid: Oid,
) -> Option<Self>where
Self: Sized,
FromDatum::from_datum(...) from within that context. Read moreSource§unsafe fn try_from_datum(
datum: Datum,
is_null: bool,
type_oid: Oid,
) -> Result<Option<Self>, TryFromDatumError>
unsafe fn try_from_datum( datum: Datum, is_null: bool, type_oid: Oid, ) -> Result<Option<Self>, TryFromDatumError>
try_from_datum is a convenience wrapper around FromDatum::from_datum that returns a
a Result around an Option, as a Datum can be null. It’s intended to be used in
situations where the caller needs to know whether the type conversion succeeded or failed. Read moreSource§unsafe fn try_from_datum_in_memory_context(
memory_context: PgMemoryContexts,
datum: Datum,
is_null: bool,
type_oid: Oid,
) -> Result<Option<Self>, TryFromDatumError>
unsafe fn try_from_datum_in_memory_context( memory_context: PgMemoryContexts, datum: Datum, is_null: bool, type_oid: Oid, ) -> Result<Option<Self>, TryFromDatumError>
try_from_datum that switches to the given context to convert from DatumSource§impl HasExtractableParts for Timestamp
impl HasExtractableParts for Timestamp
const EXTRACT_FUNCTION: unsafe fn(*mut FunctionCallInfoBaseData) -> Datum = {pgrx::pg_sys::extract_timestamp as unsafe fn(*mut pgrx::pg_sys::FunctionCallInfoBaseData) -> pgrx::pg_sys::Datum}
Source§fn extract_part(&self, field: DateTimeParts) -> Option<AnyNumeric>
fn extract_part(&self, field: DateTimeParts) -> Option<AnyNumeric>
DateTimeParts part from a date/time-like typeSource§impl Ord for Timestamp
impl Ord for Timestamp
Source§fn cmp(&self, other: &Timestamp) -> Ordering
fn cmp(&self, other: &Timestamp) -> Ordering
Uses the underlying Postgres “_cmp()” function for this type
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
Source§impl RangeSubType for Timestamp
for Timestamp/tsrange
impl RangeSubType for Timestamp
for Timestamp/tsrange
fn range_type_oid() -> Oid
Source§impl Serialize for Timestamp
impl Serialize for Timestamp
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serialize this Timestamp in ISO form, compatible with most JSON parsers
Source§impl SqlTranslatable for Timestamp
impl SqlTranslatable for Timestamp
fn argument_sql() -> Result<SqlMapping, ArgumentError>
fn return_sql() -> Result<Returns, ReturnsError>
fn type_name() -> &'static str
fn variadic() -> bool
fn optional() -> bool
fn entity() -> FunctionMetadataTypeEntity
Source§impl ToIsoString for Timestamp
impl ToIsoString for Timestamp
Source§fn to_iso_string(self) -> String
fn to_iso_string(self) -> String
Source§fn to_iso_string_with_timezone<Tz>(
self,
timezone: Tz,
) -> Result<String, DateTimeConversionError>
fn to_iso_string_with_timezone<Tz>( self, timezone: Tz, ) -> Result<String, DateTimeConversionError>
impl Copy for Timestamp
impl Eq 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.