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
SlidingWindowwhen two-digit years could span two adjacent centuries and you want to bias towards a particular era. - Use
Alwayswhen all two-digit years belong to the same century without ambiguity (e.g. children’s birthdays are all in the 2000s). - Use
Literalwhen 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: i32The 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: SlidingWindowPivotThe 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
impl Clone for TwoDigitYearExpansion
Source§fn clone(&self) -> TwoDigitYearExpansion
fn clone(&self) -> TwoDigitYearExpansion
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more