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::{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.
§Errors
The DateTimeError PostgreSQL raises, the session state the literal needs and the
context lacks, or DateTimeError::OutsideJiffRange where an IANA zone is asked about
a date outside jiff’s years.
use sql_values::{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");
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 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");Trait Implementations§
impl Copy for PgTimeTz
Source§impl<'de> Deserialize<'de> for PgTimeTz
impl<'de> Deserialize<'de> for PgTimeTz
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>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for PgTimeTz
Source§impl Ord for PgTimeTz
impl Ord for PgTimeTz
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for PgTimeTz
impl PartialOrd for PgTimeTz
impl StructuralPartialEq for PgTimeTz
Auto Trait Implementations§
impl Forget for PgTimeTz
impl Freeze for PgTimeTz
impl RefUnwindSafe for PgTimeTz
impl Send for PgTimeTz
impl Sync for PgTimeTz
impl Unpin for PgTimeTz
impl UnsafeUnpin for PgTimeTz
impl UnwindSafe for PgTimeTz
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
Mutably borrows from an owned value. Read more