pub struct PgTimeTz { /* private fields */ }Expand description
A PostgreSQL timetz, a time of day with the offset east of UTC it was written with,
ordered by the instant and then by the offset, as timetz_cmp orders it.
use sql_values::postgres::{PgTime, PgTimeTz};
let noon = PgTime::from_hms_micro(12, 0, 0, 0).unwrap();
let rome = PgTimeTz::new(noon, 3_600).unwrap();
assert_eq!(rome.to_string(), "12:00:00+01");
let utc = PgTimeTz::new(PgTime::from_hms_micro(11, 0, 0, 0).unwrap(), 0).unwrap();
// At one instant the offset decides, by PostgreSQL's zone in seconds west of UTC.
assert_ne!(rome, utc);
assert!(rome < utc);Implementations§
Source§impl PgTimeTz
impl PgTimeTz
Sourcepub fn parse(
text: &str,
context: InputContext<'_>,
) -> Result<Self, DateTimeError>
pub fn parse( text: &str, context: InputContext<'_>, ) -> Result<Self, DateTimeError>
PostgreSQL’s timetz_in, reading every spelling DecodeTimeOnly reads. A time without
an offset, or with a zone whose offset changes, takes the zone’s offset on the date the
literal writes, or else on the current date in the context’s time zone. A context time
zone with one offset on every date gives it without the current date.
§Errors
The DateTimeError PostgreSQL raises, or the session state the literal needs and the
context lacks.
use sql_values::postgres::{
DateTimeError, InputContext, PgTimeTz, PgTimeZone, PgTimestampTz,
};
let read = |text, context| PgTimeTz::parse(text, context).map(|t| t.to_string());
let context = InputContext::new();
assert_eq!(read("12:00:00-05:30", context).unwrap(), "12:00:00-05:30");
assert_eq!(read("allballs", context).unwrap(), "00:00:00+00");
#[cfg(feature = "tzdb")]
assert_eq!(read("2026-07-01 12:00 Europe/Rome", context).unwrap(), "12:00:00+02");
assert_eq!(read("12:00", context), Err(DateTimeError::NeedsCurrentTime));
let gmt = PgTimeZone::parse("GMT").unwrap();
assert_eq!(read("12:00", context.with_time_zone(&gmt)).unwrap(), "12:00:00+00");
#[cfg(feature = "tzdb")]
{
let rome = PgTimeZone::parse("Europe/Rome").unwrap();
let start = PgTimestampTz::parse("2026-01-15 12:00+00", context).unwrap();
let session = context.with_time_zone(&rome).with_now(start);
assert_eq!(read("12:00", session).unwrap(), "12:00:00+01");
}Source§impl PgTimeTz
impl PgTimeTz
Source§impl PgTimeTz
impl PgTimeTz
Sourcepub fn extract(
self,
field: ExtractField,
) -> Result<Option<PgNumeric>, ExtractError>
pub fn extract( self, field: ExtractField, ) -> Result<Option<PgNumeric>, ExtractError>
PostgreSQL’s extract(field FROM timetz), the clock as written and its own offset.
§Errors
ExtractError::UnsupportedField for a field other than a clock or zone field or
epoch.
use sql_values::postgres::{ExtractField, PgNumeric, PgTime, PgTimeTz};
let time = PgTime::from_hms_micro(12, 34, 56, 0).unwrap();
let india = PgTimeTz::new(time, 19_800).unwrap();
assert_eq!(india.extract(ExtractField::TimezoneMinute).unwrap(), Some(PgNumeric::from(30)));Sourcepub fn date_part(
self,
field: ExtractField,
) -> Result<Option<PgFloat8>, ExtractError>
pub fn date_part( self, field: ExtractField, ) -> Result<Option<PgFloat8>, ExtractError>
PostgreSQL’s date_part(field, timetz).
§Errors
ExtractError::UnsupportedField for a field other than a clock or zone field or
epoch.