pub struct PgTimestamp(/* private fields */);Expand description
A PostgreSQL timestamp, microseconds from 2000-01-01 00:00:00, from 4714-11-24 BC to
294276-12-31 23:59:59.999999 and the two infinities.
use sql_values::postgres::{InputContext, PgTimestamp};
let last = PgTimestamp::parse("294276-12-31 23:59:59.999999", InputContext::new()).unwrap();
assert_eq!(last.to_string(), "294276-12-31 23:59:59.999999");
assert_eq!(PgTimestamp::INFINITY.to_string(), "infinity");
assert!(last < PgTimestamp::INFINITY);Implementations§
Source§impl PgTimestamp
impl PgTimestamp
Sourcepub fn parse(
text: &str,
context: InputContext<'_>,
) -> Result<Self, DateTimeError>
pub fn parse( text: &str, context: InputContext<'_>, ) -> Result<Self, DateTimeError>
PostgreSQL’s timestamp_in, reading every spelling DecodeDateTime reads, with a zone
read, checked and ignored.
§Errors
The DateTimeError PostgreSQL raises, or the session state the literal needs and the
context lacks.
use sql_values::postgres::{DateTimeError, InputContext, PgTimestamp};
let read = |text| PgTimestamp::parse(text, InputContext::new()).map(|t| t.to_string());
assert_eq!(read("2024-12-31 24:00:00").unwrap(), "2025-01-01 00:00:00");
assert_eq!(read("Jan 1999 08 04:05:06 PM").unwrap(), "1999-01-08 16:05:06");
assert_eq!(read("19990108T040506.5").unwrap(), "1999-01-08 04:05:06.5");
assert_eq!(read("294277-01-01"), Err(DateTimeError::TimestampOutOfRange));Source§impl PgTimestamp
impl PgTimestamp
Sourcepub const NEG_INFINITY: Self
pub const NEG_INFINITY: Self
-infinity, PostgreSQL’s DT_NOBEGIN, before every timestamp.
Sourcepub const fn from_pg_micros(micros: i64) -> Option<Self>
pub const fn from_pg_micros(micros: i64) -> Option<Self>
The timestamp micros microseconds after 2000-01-01 00:00:00, as PostgreSQL stores it,
where i64::MAX and i64::MIN are the infinities, or None outside PostgreSQL’s range.
Sourcepub fn new(date: PgDate, time: PgTime) -> Option<Self>
pub fn new(date: PgDate, time: PgTime) -> Option<Self>
The timestamp of time on a finite date, where 24:00:00 is midnight of the next day,
or None for an infinite date or outside PostgreSQL’s range.
use sql_values::postgres::{PgDate, PgTime, PgTimestamp};
let date = PgDate::from_ymd(2024, 12, 31).unwrap();
let at = PgTimestamp::new(date, PgTime::from_micros(86_400_000_000).unwrap()).unwrap();
assert_eq!(at.to_string(), "2025-01-01 00:00:00");Sourcepub const fn pg_micros(self) -> i64
pub const fn pg_micros(self) -> i64
Microseconds from 2000-01-01 00:00:00, as PostgreSQL stores the timestamp.
Sourcepub fn date(self) -> PgDate
pub fn date(self) -> PgDate
The date, infinite for an infinite timestamp, as timestamp_date casts it.
Sourcepub fn to_timestamptz(
self,
zone: &PgTimeZone,
) -> Result<PgTimestampTz, DateTimeError>
pub fn to_timestamptz( self, zone: &PgTimeZone, ) -> Result<PgTimestampTz, DateTimeError>
PostgreSQL’s timestamp::timestamptz with zone as the session’s TimeZone, the local
clock resolved by DetermineTimeZoneOffset. A clock the spring-forward gap skips takes
the offset before the change, and a clock the fall-back repeats the offset after it.
§Errors
DateTimeError::TimestampOutOfRange where the instant leaves PostgreSQL’s range, and
DateTimeError::OutsideJiffRange where an IANA zone is asked about a clock outside
jiff’s years.
use sql_values::postgres::{InputContext, PgTimeZone, PgTimestamp};
#[cfg(feature = "tzdb")]
{
let rome = PgTimeZone::parse("Europe/Rome").unwrap();
let gap = PgTimestamp::parse("2026-03-29 02:30:00", InputContext::new()).unwrap();
assert_eq!(gap.to_timestamptz(&rome).unwrap().to_string(), "2026-03-29 01:30:00+00");
}Trait Implementations§
Source§impl Clone for PgTimestamp
impl Clone for PgTimestamp
impl Copy for PgTimestamp
Source§impl Debug for PgTimestamp
impl Debug for PgTimestamp
Source§impl<'de> Deserialize<'de> for PgTimestamp
impl<'de> Deserialize<'de> for PgTimestamp
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 PgTimestamp
impl Display for PgTimestamp
impl Eq for PgTimestamp
Source§impl From<PgTimestamp> for i64
impl From<PgTimestamp> for i64
Source§fn from(at: PgTimestamp) -> Self
fn from(at: PgTimestamp) -> Self
Source§impl Hash for PgTimestamp
impl Hash for PgTimestamp
Source§impl Ord for PgTimestamp
impl Ord for PgTimestamp
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 PgTimestamp
impl PartialEq for PgTimestamp
Source§impl PartialOrd for PgTimestamp
impl PartialOrd for PgTimestamp
Source§impl Serialize for PgTimestamp
impl Serialize for PgTimestamp
impl StructuralPartialEq for PgTimestamp
Source§impl TryFrom<DateTime> for PgTimestamp
Refuses a timestamp before PostgreSQL’s 4714-11-24 BC.
impl TryFrom<DateTime> for PgTimestamp
Refuses a timestamp before PostgreSQL’s 4714-11-24 BC.
Source§impl TryFrom<PgTimestamp> for DateTime
Refuses a value jiff does not hold, infinity or -infinity, with jiff’s bound.
impl TryFrom<PgTimestamp> for DateTime
Refuses a value jiff does not hold, infinity or -infinity, with jiff’s bound.