pub struct DateTime(pub OffsetDateTime);Expand description
An RFC 3339 date-time, the wire form of OpenAPI’s format: date-time.
Tuple Fields§
§0: OffsetDateTimeImplementations§
Source§impl DateTime
impl DateTime
Sourcepub fn into_inner(self) -> OffsetDateTime
pub fn into_inner(self) -> OffsetDateTime
The wrapped time value.
Source§impl DateTime
impl DateTime
Sourcepub fn parse_strict(text: &str) -> Result<Self, ParseError>
pub fn parse_strict(text: &str) -> Result<Self, ParseError>
Parse an RFC 3339 date-time exactly: YYYY-MM-DDTHH:MM:SS[.fraction](Z|±HH:MM), with an
upper-case T and Z, a year from 0001, a real calendar day and no leap second.
Sourcepub fn parse_lenient(text: &str) -> Result<Self, ParseError>
pub fn parse_lenient(text: &str) -> Result<Self, ParseError>
As parse_strict, but seconds may be omitted (HH:MM), T and Z
may be lower case (RFC 3339 §5.6) and the year may be 0000: every value a contract with a
date-time format or its own pattern may carry.
Methods from Deref<Target = OffsetDateTime>§
pub const UNIX_EPOCH: OffsetDateTime
Trait Implementations§
impl Copy for DateTime
Source§impl<'de> Deserialize<'de> for DateTime
impl<'de> Deserialize<'de> for DateTime
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Lenient (see DateTime::parse_lenient), so no value the contract allows is refused.
Source§impl Display for DateTime
impl Display for DateTime
Source§fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
The RFC 3339 rendering — the same bytes Serialize writes.
This matters beyond convenience: a multipart/form-data text part and a text/plain body
are rendered through Display, so a Display that disagreed with Serialize would put two
different encodings of the same value on the wire depending on the body’s media type.
RFC 3339 fixes the year at four digits, so a year outside 0..=9999 — which time can hold
but RFC 3339 cannot express — has no rendering here. It falls back to time’s own form
rather than failing, because Display failure would panic through to_string() at exactly
those two call sites. Serialize still refuses such a value, so it can never reach a JSON
body claiming to be RFC 3339.