pub struct PgTimestampTz(/* private fields */);Expand description
A PostgreSQL timestamptz, the instant as microseconds from 2000-01-01 00:00:00 UTC, over the
range of PgTimestamp, printed as under TimeZone UTC.
use sql_values::{InputContext, PgTimestampTz};
let at = PgTimestampTz::parse("2026-03-29 12:00:00+02", InputContext::new()).unwrap();
assert_eq!(at.to_string(), "2026-03-29 10:00:00+00");Implementations§
Source§impl PgTimestampTz
impl PgTimestampTz
Sourcepub fn parse(
text: &str,
context: InputContext<'_>,
) -> Result<Self, DateTimeError>
pub fn parse( text: &str, context: InputContext<'_>, ) -> Result<Self, DateTimeError>
PostgreSQL’s timestamptz_in, reading the ISO spelling and infinity, -infinity and
epoch. A zone the literal names, or else the context’s time zone, decides the offset of
a literal without a numeric one, its local clock resolved as
PgTimestamp::to_timestamptz resolves it, and an abbreviation whose meaning changed
takes the one it had at that clock.
§Errors
The DateTimeError PostgreSQL raises, DateTimeError::NeedsTimeZone for a literal
without an offset or zone and a context without a time zone,
DateTimeError::OutsideJiffRange where an IANA zone is asked about a clock outside
jiff’s years, or DateTimeError::Unsupported for another spelling.
use sql_values::{DateTimeError, InputContext, PgTimestampTz};
let read = |text| PgTimestampTz::parse(text, InputContext::new()).map(|t| t.to_string());
assert_eq!(read("2024-01-01 12:00+15:59:59").unwrap(), "2023-12-31 20:00:01+00");
assert_eq!(read("2024-01-01 12:00+16"), Err(DateTimeError::TimeZoneDisplacementOutOfRange));
// `MSK` follows Europe/Moscow, which kept +04 from 2011 to 2014.
assert_eq!(read("2012-01-01 12:00 MSK").unwrap(), "2012-01-01 08:00:00+00");
assert_eq!(read("2015-01-01 12:00 MSK").unwrap(), "2015-01-01 09:00:00+00");Source§impl PgTimestampTz
impl PgTimestampTz
Sourcepub const NEG_INFINITY: Self
pub const NEG_INFINITY: Self
-infinity, PostgreSQL’s DT_NOBEGIN, before every instant.
Sourcepub const fn from_pg_micros(micros: i64) -> Option<Self>
pub const fn from_pg_micros(micros: i64) -> Option<Self>
The instant micros microseconds after 2000-01-01 00:00:00 UTC, as PostgreSQL stores it,
where i64::MAX and i64::MIN are the infinities, or None outside PostgreSQL’s range.
Sourcepub const fn pg_micros(self) -> i64
pub const fn pg_micros(self) -> i64
Microseconds from 2000-01-01 00:00:00 UTC, as PostgreSQL stores the instant.
Sourcepub fn to_timestamp(
self,
zone: &PgTimeZone,
) -> Result<PgTimestamp, DateTimeError>
pub fn to_timestamp( self, zone: &PgTimeZone, ) -> Result<PgTimestamp, DateTimeError>
PostgreSQL’s timestamptz::timestamp with zone as the session’s TimeZone, the local
clock of the instant.
§Errors
DateTimeError::TimestampOutOfRange where the local clock leaves PostgreSQL’s range,
and DateTimeError::OutsideJiffRange where an IANA zone is asked about an instant
outside jiff’s years.
use sql_values::{InputContext, PgTimeZone, PgTimestampTz};
let sydney = PgTimeZone::parse("Australia/Sydney").unwrap();
let at = PgTimestampTz::parse("2026-01-01 00:00:00+00", InputContext::new()).unwrap();
assert_eq!(at.to_timestamp(&sydney).unwrap().to_string(), "2026-01-01 11:00:00");Sourcepub fn to_date(self, zone: &PgTimeZone) -> Result<PgDate, DateTimeError>
pub fn to_date(self, zone: &PgTimeZone) -> Result<PgDate, DateTimeError>
PostgreSQL’s timestamptz::date with zone as the session’s TimeZone, the local date
of the instant, which PostgreSQL does not range-check.
§Errors
DateTimeError::OutsideJiffRange where an IANA zone is asked about an instant outside
jiff’s years.
Trait Implementations§
Source§impl Clone for PgTimestampTz
impl Clone for PgTimestampTz
impl Copy for PgTimestampTz
Source§impl Debug for PgTimestampTz
impl Debug for PgTimestampTz
Source§impl<'de> Deserialize<'de> for PgTimestampTz
impl<'de> Deserialize<'de> for PgTimestampTz
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 Display for PgTimestampTz
impl Display for PgTimestampTz
impl Eq for PgTimestampTz
Source§impl From<PgTimestampTz> for i64
impl From<PgTimestampTz> for i64
Source§fn from(at: PgTimestampTz) -> Self
fn from(at: PgTimestampTz) -> Self
Source§impl Hash for PgTimestampTz
impl Hash for PgTimestampTz
Source§impl Ord for PgTimestampTz
impl Ord for PgTimestampTz
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for PgTimestampTz
impl PartialEq for PgTimestampTz
Source§impl PartialOrd for PgTimestampTz
impl PartialOrd for PgTimestampTz
Source§impl Serialize for PgTimestampTz
impl Serialize for PgTimestampTz
impl StructuralPartialEq for PgTimestampTz
Source§impl TryFrom<PgTimestampTz> for Timestamp
Refuses a value jiff does not hold, infinity or -infinity, with jiff’s bound.
impl TryFrom<PgTimestampTz> for Timestamp
Refuses a value jiff does not hold, infinity or -infinity, with jiff’s bound.
Source§type Error = DateTimeError
type Error = DateTimeError
Source§impl TryFrom<Timestamp> for PgTimestampTz
Refuses an instant before PostgreSQL’s 4714-11-24 BC.
impl TryFrom<Timestamp> for PgTimestampTz
Refuses an instant before PostgreSQL’s 4714-11-24 BC.