Skip to main content

TwoDigitYearExpansion

Enum TwoDigitYearExpansion 

Source
pub enum TwoDigitYearExpansion {
    SlidingWindow {
        earliest_year: i32,
        pivot: SlidingWindowPivot,
    },
    Always(Century),
    Literal,
}
Expand description

Strategy for expanding two-digit years into four-digit years.

§Choosing a strategy

  • Use SlidingWindow when two-digit years could span two adjacent centuries and you want to bias towards a particular era.
  • Use Always when all two-digit years belong to the same century without ambiguity (e.g. children’s birthdays are all in the 2000s).
  • Use Literal when you want the two-digit value kept as-is (e.g. historical records where the year is genuinely in the range 0–99).

Variants§

§

SlidingWindow

Splits the 100 possible two-digit values across two adjacent centuries.

earliest_year is the smallest year the window can ever produce — it is the year that two-digit value pivot maps to. Values pivot..=99 map to earliest_year..=(earliest_year + (99 - pivot)), and values 0..(pivot) map to (earliest_year + (100 - pivot))..(earliest_year + 99).

§Example

use partial_date::models::{SlidingWindowPivot, TwoDigitYearExpansion};

// 00–49 → 2000–2049, 50–99 → 1950–1999 (the default).
let expansion = TwoDigitYearExpansion::SlidingWindow {
    earliest_year: 1950,
    pivot: SlidingWindowPivot::new(50),
};

// Industrial Revolution era: 00–49 → 1800–1849, 50–99 → 1750–1799.
let expansion = TwoDigitYearExpansion::SlidingWindow {
    earliest_year: 1750,
    pivot: SlidingWindowPivot::new(50),
};

Fields

§earliest_year: i32

The smallest year this window can produce (the year pivot maps to). Must be chosen so that the full window [earliest_year, earliest_year + 99] covers the values you intend to accept. Use YearConfig::min and YearConfig::max to reject any expanded years that fall outside your valid range.

§pivot: SlidingWindowPivot

The two-digit value at which the window wraps from the lower (earlier) century to the upper (more recent) century.

§

Always(Century)

Maps all two-digit values into a single century.

00 maps to the century start, 99 maps to century + 99.

§Example

use partial_date::models::{Century, TwoDigitYearExpansion};

// All two-digit years are in the 2000s: 00 → 2000, 34 → 2034.
let expansion = TwoDigitYearExpansion::Always(Century::new(2000));

// All two-digit years are in the 1800s: 00 → 1800, 34 → 1834.
let expansion = TwoDigitYearExpansion::Always(Century::new(1800));
§

Literal

Return the two-digit value literally (e.g. 24 stays as 24).

Useful when processing historical records where the year genuinely falls in the range 0–99, or when you want to apply your own post-processing.

Trait Implementations§

Source§

impl Clone for TwoDigitYearExpansion

Source§

fn clone(&self) -> TwoDigitYearExpansion

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 TwoDigitYearExpansion

Source§

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

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

impl Default for TwoDigitYearExpansion

Source§

fn default() -> Self

The standard modern sliding window: 00–49 → 2000–2049, 50–99 → 1950–1999.

Source§

impl PartialEq for TwoDigitYearExpansion

Source§

fn eq(&self, other: &TwoDigitYearExpansion) -> 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 Copy for TwoDigitYearExpansion

Source§

impl Eq for TwoDigitYearExpansion

Source§

impl StructuralPartialEq for TwoDigitYearExpansion

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, 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.