pub struct PgTime(/* private fields */);Expand description
A PostgreSQL time, microseconds from midnight to 24:00:00 inclusive.
use sql_values::PgTime;
let noon = PgTime::from_hms_micro(12, 0, 0, 500_000).unwrap();
assert_eq!(noon.to_string(), "12:00:00.5");
assert_eq!(PgTime::from_micros(86_400_000_000).unwrap().to_string(), "24:00:00");Implementations§
Source§impl PgTime
impl PgTime
Sourcepub fn parse(
text: &str,
context: InputContext<'_>,
) -> Result<Self, DateTimeError>
pub fn parse( text: &str, context: InputContext<'_>, ) -> Result<Self, DateTimeError>
PostgreSQL’s time_in, reading every spelling DecodeTimeOnly reads, with a date and
zone read, checked and ignored, and the fraction rounded to the microsecond.
§Errors
The DateTimeError PostgreSQL raises, or the session state the literal needs and the
context lacks.
use sql_values::{DateTimeError, InputContext, PgTime, PgType};
let read = |text| PgTime::parse(text, InputContext::new()).map(|t| t.to_string());
assert_eq!(read("23:59:60").unwrap(), "24:00:00");
assert_eq!(read("12:00:00.1234565").unwrap(), "12:00:00.123456");
assert_eq!(read("040506.5 PM").unwrap(), "16:05:06.5");
assert_eq!(read("T12:00 Europe/Rome"), Err(DateTimeError::InvalidInputSyntax(PgType::Time)));
assert_eq!(read("2026-07-01 12:00 Europe/Rome").unwrap(), "12:00:00");
assert_eq!(read("24:00:00.000001"), Err(DateTimeError::FieldValueOutOfRange));Source§impl PgTime
impl PgTime
Sourcepub const fn from_micros(micros: i64) -> Option<Self>
pub const fn from_micros(micros: i64) -> Option<Self>
The time micros microseconds after midnight, or None outside 00:00:00 to 24:00:00.
Trait Implementations§
impl Copy for PgTime
Source§impl<'de> Deserialize<'de> for PgTime
impl<'de> Deserialize<'de> for PgTime
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 PgTime
Source§impl From<Time> for PgTime
A clock within 500 nanoseconds of midnight rounds up to 24:00:00, which PostgreSQL holds.
impl From<Time> for PgTime
A clock within 500 nanoseconds of midnight rounds up to 24:00:00, which PostgreSQL holds.
Source§impl Ord for PgTime
impl Ord for PgTime
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 PgTime
impl PartialOrd for PgTime
impl StructuralPartialEq for PgTime
Auto Trait Implementations§
impl Forget for PgTime
impl Freeze for PgTime
impl RefUnwindSafe for PgTime
impl Send for PgTime
impl Sync for PgTime
impl Unpin for PgTime
impl UnsafeUnpin for PgTime
impl UnwindSafe for PgTime
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