Skip to main content

SacOrGreg

Enum SacOrGreg 

Source
pub enum SacOrGreg {
    Gregorian(GregorianDate),
    Sac13(Date),
}
Expand description

EitherDate is either a GregorianDate or SAC13 Date.

Variants§

§

Gregorian(GregorianDate)

Variant wrapping a GregorianDate.

§

Sac13(Date)

Variant wrapping a SAC13 Date.

Implementations§

Source§

impl SacOrGreg

Source

pub fn greg(&self) -> Option<GregorianDate>

If the inner variant is SacOrGreg::Gregorian it returns that, otherwise None.

Source

pub fn sac13(&self) -> Option<Date>

If the inner variant is SacOrGreg::Sac13 it returns that, otherwise None.

Source

pub fn parse_str(input: &str) -> Option<ParsedSacOrGreg>

Parses various SAC13 and Gregorian Calendar formats.

§Example
use sac13::prelude::*;

let parsed = SacOrGreg::parse_str("2009-07-03").unwrap();
§Supported Formats
§Nomenclature
    ┌── leading whitespace
    │
    │   Separators   trailing whitespace
 ┌──┴─┐  ┌┤  │     ┌───┴───┐
"      23, 12 -2007         "
       └┤  └┤ └─┬─┘   
        Components
§Exactly three numeric components

This function only allows dates that are represented by three numeric components, including SAC13 years with millenium indicator (technically it’s a base-26 digit). In fact SAC13 years must be written with a millenium indicator because that is used to disambiguate between SAC13 and Gregorian Calendar dates. Components must not have thousands separators (or similar group separators).

Textual representations/components like Gregorian weekdays or full month names are not supported!

§Year first or last

The year component has to either be the first, or the third (and last) component. It must not be the second (middle) component. The allowed component orders are defined in the ComponentOrder enum.

If it’s a SAC13 date the year must always be exactly four digits long A000 - Z999. For Gregorian Dates if any component is negative or zero, it is automatically assumed to be the year component. Positive years must be at least three digits long so the component is clearly distinct from the month and day component. If the year is positive but less than 100 it must be written with leading zeros.

Even though the actual supported formats allow for three digit Gregorian Calendar years, or even one digit if the year is negative, the best practice is to pad years to at least four digits.

The position of the year component implicitly defines the order of month and day, because all components are either in acending or decending order. There is one special case though: If it’s Gregorian Calendar date and the separators between all components are slashes, we assume the components to be a US formatted date with the order M/D/Y

§Separators

All ASCII characters that are not letters or digits, are allowed as separators; they are one or more (at most six) characters long and can be pretty arbitrary. Again, even though you can use almost anything as separators doesn’t mean you should. You should especially avoid multi-character separators that end with dashes, because they will be interpreted as a negative sign for the next component. YYYY-MM-DD and YYYY - MM - DD are, of course, fine but using - as a separator, like in YYYY -MM -DD, will (obvously?) lead to said problem, because it will be interpreted as three components separated by spaces, with at least two of them being negative. Note that + is never interpreted as a sign. So, something like DD.- +MM+$%&/\YYYY can be parsed, but please don’t do that!

§ASCII only

The entire input must be valid ASCII. If you have some weird format, for example with emdash separators, you must replace them, for example with regular hyphens, before parsing.

§Whitespace

Only spaces (0x20) are considered “whitespace” by this method. Leading and trailing whitespace are always trimmed, no matter how long. Whitespace in separators are considered part of the separator and recorded as is in the DateComponentSeparator.

Trait Implementations§

Source§

impl Clone for SacOrGreg

Source§

fn clone(&self) -> SacOrGreg

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SacOrGreg

Source§

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

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

impl Display for SacOrGreg

Source§

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

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

impl Hash for SacOrGreg

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for SacOrGreg

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for SacOrGreg

Source§

impl StructuralPartialEq for SacOrGreg

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.