pub struct PgDate(/* private fields */);Expand description
A PostgreSQL date, days from 2000-01-01, from 4714-11-24 BC to 5874897-12-31 and the two
infinities, ordered as PostgreSQL orders it.
use sql_values::{InputContext, PgDate};
let leap = PgDate::from_ymd(2024, 2, 29).unwrap();
assert_eq!(leap.to_string(), "2024-02-29");
assert_eq!(PgDate::parse("2024-02-29", InputContext::new()), Ok(leap));
assert_eq!(PgDate::from_ymd(-4713, 11, 24).unwrap().to_string(), "4714-11-24 BC");
assert!(PgDate::from_ymd(-4713, 11, 23).is_none());
assert!(PgDate::NEG_INFINITY < leap && leap < PgDate::INFINITY);Implementations§
Source§impl PgDate
impl PgDate
Sourcepub fn parse(
text: &str,
context: InputContext<'_>,
) -> Result<Self, DateTimeError>
pub fn parse( text: &str, context: InputContext<'_>, ) -> Result<Self, DateTimeError>
PostgreSQL’s date_in, reading the ISO spelling and infinity, -infinity and epoch,
with a clock and offset read, checked and ignored.
§Errors
The DateTimeError PostgreSQL raises, or DateTimeError::Unsupported for another
spelling.
use sql_values::{DateTimeError, InputContext, PgDate};
let read = |text| PgDate::parse(text, InputContext::new()).map(|d| d.to_string());
assert_eq!(read("5874897-12-31").unwrap(), "5874897-12-31");
assert_eq!(read(" -Infinity ").unwrap(), "-infinity");
assert_eq!(read("2024-02-30"), Err(DateTimeError::FieldValueOutOfRange));
assert_eq!(read("4714-11-23 BC"), Err(DateTimeError::DateOutOfRange));Source§impl PgDate
impl PgDate
Sourcepub const NEG_INFINITY: Self
pub const NEG_INFINITY: Self
-infinity, PostgreSQL’s DATEVAL_NOBEGIN, before every date.
Sourcepub fn from_ymd(year: i32, month: u8, day: u8) -> Option<Self>
pub fn from_ymd(year: i32, month: u8, day: u8) -> Option<Self>
The date of the proleptic Gregorian year, month and day, where year Y BC is year
1 - Y, or None outside the calendar or PostgreSQL’s dates.
Sourcepub const fn from_pg_days(days: i32) -> Option<Self>
pub const fn from_pg_days(days: i32) -> Option<Self>
The date days after 2000-01-01, as PostgreSQL stores it, where i32::MAX and i32::MIN
are the infinities, or None outside PostgreSQL’s dates.
Trait Implementations§
impl Copy for PgDate
Source§impl<'de> Deserialize<'de> for PgDate
impl<'de> Deserialize<'de> for PgDate
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 PgDate
Source§impl Ord for PgDate
impl Ord for PgDate
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 PgDate
impl PartialOrd for PgDate
impl StructuralPartialEq for PgDate
Auto Trait Implementations§
impl Forget for PgDate
impl Freeze for PgDate
impl RefUnwindSafe for PgDate
impl Send for PgDate
impl Sync for PgDate
impl Unpin for PgDate
impl UnsafeUnpin for PgDate
impl UnwindSafe for PgDate
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