Skip to main content

DateFormat

Struct DateFormat 

Source
pub struct DateFormat { /* private fields */ }
Expand description

A source’s spelling, read once.

Built from the authored text and never rebuilt: every engine translates the same list, so two engines cannot disagree about what the design said.

Implementations§

Source§

impl DateFormat

Source

pub fn parse(spelled: &str) -> Result<Self, DateFormatError>

Read a format, or say what is wrong with it.

§Errors

A % followed by a letter outside the family, a % at the end with nothing after it, or nothing at all.

Source

pub fn spelled(&self) -> &str

The format as the design wrote it — what a refusal quotes back.

Source

pub fn parts(&self) -> &[FormatPart]

The pieces, in the order the value writes them.

Source

pub fn directives(&self) -> impl Iterator<Item = FormatDirective> + '_

Every directive the format says, in order, literals passed over.

Source

pub fn names_a_zone(&self) -> bool

True where the format carries an offset or a zone name — the two things a column holding a day alone has nowhere to put.

Source

pub fn says_a_time_of_day(&self) -> bool

True where the format says anything about the time within a day.

Source

pub fn translate( &self, spell: &dyn Fn(FormatDirective) -> Option<&'static str>, literal: &dyn Fn(&str) -> String, ) -> Result<String, FormatDirective>

Translate the format into one engine’s own pattern language, directive by directive.

spell answers with this engine’s token for one directive, or None where the engine has no way to say it; literal writes a run of literal text the way this engine’s patterns want it, which on some is the text as it stands and on others is the text in quotes.

§Errors

The first directive spell answered None for — which is what the refusal names, so an author is told which part of their format this engine cannot read rather than that the format failed.

Source

pub fn shape_pattern(&self) -> String

A guard against a value spelled some other way, as an anchored POSIX regular expression that holds every field to its own range.

It is for the engines that read a value they cannot read: hand 13/45/2015 to a parse that rolls fields over and it answers a day in 2016 rather than answering nothing. The guard is built from the same list the parse is, so the two cannot disagree about what the design said.

What it holds and what it does not. Every field is held to its own range — a month is 1 to 12, an hour is 0 to 23 — so a value written some other way, or holding a number no calendar has, is caught. A day that is in range and yet not in its month, the thirty-first of a thirty-day month, is not a question a shape can answer; the engines that need this guard say in their own rendering what they do about it.

Source

pub fn capture_pattern(&self, wanted: FormatDirective) -> Option<String>

Read one field back out of the value, as an anchored POSIX regular expression with exactly one capturing group around the field asked for.

Everything else in it is loose and ungrouped, so the group an engine reads back is the first one and the only one — which is the most any of the engines needing it can address.

None where the format does not say that field at all.

Trait Implementations§

Source§

impl Clone for DateFormat

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DateFormat

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for DateFormat

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for DateFormat

Source§

impl PartialEq for DateFormat

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DateFormat

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.