pub struct InputContext<'a> { /* private fields */ }Expand description
The session state PostgreSQL’s input functions read, which the caller supplies.
use sql_values::postgres::{
DateTimeError, InputContext, PgTimeZone, PgTimestampTz, TimeZoneAbbreviations,
};
let local = "2026-07-01 12:00:00";
assert_eq!(
PgTimestampTz::parse(local, InputContext::new()),
Err(DateTimeError::NeedsTimeZone),
);
#[cfg(feature = "tzdb")]
{
let rome = PgTimeZone::parse("Europe/Rome").unwrap();
let at = PgTimestampTz::parse(local, InputContext::new().with_time_zone(&rome)).unwrap();
assert_eq!(at.to_string(), "2026-07-01 10:00:00+00");
}
// `EST` is New York's time in `Default` and Brisbane's in `Australia`.
let australia = TimeZoneAbbreviations::bundled("Australia").unwrap();
let context = InputContext::new().with_time_zone_abbreviations(australia);
let est = PgTimestampTz::parse("2026-07-01 12:00 EST", context).unwrap();
assert_eq!(est.to_string(), "2026-07-01 02:00:00+00");Implementations§
Source§impl<'a> InputContext<'a>
impl<'a> InputContext<'a>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
A context with no time zone, no DateStyle order and no current time, and the Default
abbreviations, as a stock installation’s timezone_abbreviations names them.
Sourcepub const fn with_time_zone(self, zone: &'a PgTimeZone) -> Self
pub const fn with_time_zone(self, zone: &'a PgTimeZone) -> Self
The context with zone as the session’s TimeZone, which reads a timestamptz or
timetz written without an offset, and whose own abbreviations a literal may write
before those of the set.
Sourcepub const fn with_time_zone_abbreviations(
self,
abbreviations: &'a TimeZoneAbbreviations,
) -> Self
pub const fn with_time_zone_abbreviations( self, abbreviations: &'a TimeZoneAbbreviations, ) -> Self
The context with abbreviations as the session’s timezone_abbreviations.
Sourcepub const fn with_date_order(self, order: DateOrder) -> Self
pub const fn with_date_order(self, order: DateOrder) -> Self
The context with order as the field order of the session’s DateStyle, which reads a
date written in numbers alone such as 01/02/2026.
Sourcepub const fn with_now(self, now: PgTimestampTz) -> Self
pub const fn with_now(self, now: PgTimestampTz) -> Self
The context with now as the transaction’s start, which now, today, tomorrow and
yesterday read, in the context’s time zone, and whose date a timetz without a date
takes its zone’s offset on. An infinite now reads as
DateTimeError::TimestampOutOfRange, as no transaction starts at one.