Skip to main content

Config

Struct Config 

Source
pub struct Config {
    pub day: DayConfig,
    pub month: MonthConfig,
    pub year: YearConfig,
    pub component_order: ComponentOrder,
    pub no_separator: bool,
    pub extra_separators: Vec<String>,
    pub letter_o_substitution: bool,
}
Expand description

Top-level configuration for the extractor.

The extractor always tries all standard separators (/, -, ., ,, \, and whitespace) automatically — no separator needs to be specified. Use Config::no_separator to enable parsing of fully concatenated date strings (e.g. "25122024"), and Config::extra_separators to add custom separator strings (e.g. "||", " - ").

Construct via Config::default() and override only the fields you need, or build a fully custom config by setting each field explicitly.

Fields§

§day: DayConfig

Configuration for day extraction.

§month: MonthConfig

Configuration for month extraction.

§year: YearConfig

Configuration for year extraction.

§component_order: ComponentOrder

The expected ordering of date components for positional (numeric) inputs. Default: Day → Month → Year. See ComponentOrder.

§no_separator: bool

When true, the extractor also attempts to parse fully concatenated date strings with no separator (e.g. "25122024"). Default: false.

§extra_separators: Vec<String>

Additional custom separator strings to try alongside the standard set. Default: empty. Example: vec!["||".to_string(), " - ".to_string()].

§letter_o_substitution: bool

When true, the tokeniser substitutes the letter O (upper or lower case) for the digit 0 inside tokens that consist entirely of digits and the letter O — for example "2O24" is treated as "2024".

This handles OCR and keyboard-entry errors where the letter O is typed in place of zero. The substitution is applied only to tokens that would otherwise be entirely numeric-with-O; it is never applied when the O appears as part of a longer alphabetic run (e.g. "7october" — the "october" portion is left as-is and classified as a month name).

Default: true.

Implementations§

Source§

impl Config

Source

pub fn with_day(self, day: DayConfig) -> Self

Set the day extraction configuration.

use partial_date::models::{Config, DayConfig, IsExpected};

let config = Config::default()
    .with_day(DayConfig::default().with_range(1, 28).with_expected(IsExpected::Yes));
Examples found in repository?
examples/console_entry_config.rs (lines 81-84)
75    pub fn get_config(&self) -> Config {
76        match self {
77            // Strictly day-first numeric dates with all three components
78            // required. Letter-O substitution is disabled since this scenario
79            // expects clean numeric input only.
80            PreDefinedConfigs::StrictDMY => Config::default()
81                .with_day(
82                    DayConfig::default()
83                        .with_expected(IsExpected::Yes),
84                )
85                .with_month(
86                    MonthConfig::default()
87                        .with_expected(IsExpected::Yes)
88                )
89                .with_year(
90                    YearConfig::default()
91                        .with_range(1, 3000)
92                        .with_expected(IsExpected::Yes)
93                        .with_two_digit_expansion(TwoDigitYearExpansion::Literal),
94                )
95                .with_component_order(
96                    ComponentOrder::new(
97                        DateComponent::Day,
98                        DateComponent::Month,
99                        DateComponent::Year,
100                    )
101                    .unwrap(),
102                )
103                .with_letter_o_substitution(false),
104
105            // Wide ranging historical dates that cannot use 2-digit year
106            // expansion as there is no way to know which centuries the dates
107            // will be from. Minimal assumptions about the data when there is
108            // a lot of uncertainty.
109            PreDefinedConfigs::AllHistoricalDates => Config::default().with_year(
110                YearConfig::default()
111                    .with_range(1, 3000)
112                    .with_expected(IsExpected::Yes)
113                    .with_two_digit_expansion(TwoDigitYearExpansion::Literal),
114            ),
115
116            // Constrains the year range to the Industrial Revolution period and
117            // uses a sliding window for 2-digit years centred on 1800.
118            // Component order matches Great Britain's common DD/MM/YYYY format.
119            PreDefinedConfigs::IndustrialRevolutionDates => Config::default()
120                .with_year(
121                    YearConfig::default()
122                        .with_range(1760, 1840)
123                        .with_expected(IsExpected::Yes)
124                        .with_two_digit_expansion(TwoDigitYearExpansion::SlidingWindow {
125                            earliest_year: 1750,
126                            pivot: SlidingWindowPivot::new(50),
127                        }),
128                )
129                .with_component_order(
130                    ComponentOrder::new(
131                        DateComponent::Day,
132                        DateComponent::Month,
133                        DateComponent::Year,
134                    )
135                    .unwrap(),
136                ),
137
138            // Children under 18 — birth years must be in the 2000s and not in
139            // the future. Always(Century(2000)) maps all 2-digit values to the
140            // 2000s; the max of 2026 rejects future years.
141            PreDefinedConfigs::ChildrenBirthdays => Config::default().with_year(
142                YearConfig::default()
143                    .with_range(2000, 2026)
144                    .with_expected(IsExpected::Yes)
145                    .with_two_digit_expansion(TwoDigitYearExpansion::Always(Century::new(2000)))
146                    .with_single_digit_expansion(true),
147            ),
148        }
149    }
Source

pub fn with_month(self, month: MonthConfig) -> Self

Set the month extraction configuration.

use partial_date::models::{Config, IsExpected, MonthConfig};

let config = Config::default()
    .with_month(MonthConfig::default().with_expected(IsExpected::Yes));
Examples found in repository?
examples/console_entry_config.rs (lines 85-88)
75    pub fn get_config(&self) -> Config {
76        match self {
77            // Strictly day-first numeric dates with all three components
78            // required. Letter-O substitution is disabled since this scenario
79            // expects clean numeric input only.
80            PreDefinedConfigs::StrictDMY => Config::default()
81                .with_day(
82                    DayConfig::default()
83                        .with_expected(IsExpected::Yes),
84                )
85                .with_month(
86                    MonthConfig::default()
87                        .with_expected(IsExpected::Yes)
88                )
89                .with_year(
90                    YearConfig::default()
91                        .with_range(1, 3000)
92                        .with_expected(IsExpected::Yes)
93                        .with_two_digit_expansion(TwoDigitYearExpansion::Literal),
94                )
95                .with_component_order(
96                    ComponentOrder::new(
97                        DateComponent::Day,
98                        DateComponent::Month,
99                        DateComponent::Year,
100                    )
101                    .unwrap(),
102                )
103                .with_letter_o_substitution(false),
104
105            // Wide ranging historical dates that cannot use 2-digit year
106            // expansion as there is no way to know which centuries the dates
107            // will be from. Minimal assumptions about the data when there is
108            // a lot of uncertainty.
109            PreDefinedConfigs::AllHistoricalDates => Config::default().with_year(
110                YearConfig::default()
111                    .with_range(1, 3000)
112                    .with_expected(IsExpected::Yes)
113                    .with_two_digit_expansion(TwoDigitYearExpansion::Literal),
114            ),
115
116            // Constrains the year range to the Industrial Revolution period and
117            // uses a sliding window for 2-digit years centred on 1800.
118            // Component order matches Great Britain's common DD/MM/YYYY format.
119            PreDefinedConfigs::IndustrialRevolutionDates => Config::default()
120                .with_year(
121                    YearConfig::default()
122                        .with_range(1760, 1840)
123                        .with_expected(IsExpected::Yes)
124                        .with_two_digit_expansion(TwoDigitYearExpansion::SlidingWindow {
125                            earliest_year: 1750,
126                            pivot: SlidingWindowPivot::new(50),
127                        }),
128                )
129                .with_component_order(
130                    ComponentOrder::new(
131                        DateComponent::Day,
132                        DateComponent::Month,
133                        DateComponent::Year,
134                    )
135                    .unwrap(),
136                ),
137
138            // Children under 18 — birth years must be in the 2000s and not in
139            // the future. Always(Century(2000)) maps all 2-digit values to the
140            // 2000s; the max of 2026 rejects future years.
141            PreDefinedConfigs::ChildrenBirthdays => Config::default().with_year(
142                YearConfig::default()
143                    .with_range(2000, 2026)
144                    .with_expected(IsExpected::Yes)
145                    .with_two_digit_expansion(TwoDigitYearExpansion::Always(Century::new(2000)))
146                    .with_single_digit_expansion(true),
147            ),
148        }
149    }
Source

pub fn with_year(self, year: YearConfig) -> Self

Set the year extraction configuration.

use partial_date::models::{Config, IsExpected, YearConfig};

let config = Config::default()
    .with_year(YearConfig::default().with_range(1760, 1840).with_expected(IsExpected::Yes));
Examples found in repository?
examples/console_entry_config.rs (lines 89-94)
75    pub fn get_config(&self) -> Config {
76        match self {
77            // Strictly day-first numeric dates with all three components
78            // required. Letter-O substitution is disabled since this scenario
79            // expects clean numeric input only.
80            PreDefinedConfigs::StrictDMY => Config::default()
81                .with_day(
82                    DayConfig::default()
83                        .with_expected(IsExpected::Yes),
84                )
85                .with_month(
86                    MonthConfig::default()
87                        .with_expected(IsExpected::Yes)
88                )
89                .with_year(
90                    YearConfig::default()
91                        .with_range(1, 3000)
92                        .with_expected(IsExpected::Yes)
93                        .with_two_digit_expansion(TwoDigitYearExpansion::Literal),
94                )
95                .with_component_order(
96                    ComponentOrder::new(
97                        DateComponent::Day,
98                        DateComponent::Month,
99                        DateComponent::Year,
100                    )
101                    .unwrap(),
102                )
103                .with_letter_o_substitution(false),
104
105            // Wide ranging historical dates that cannot use 2-digit year
106            // expansion as there is no way to know which centuries the dates
107            // will be from. Minimal assumptions about the data when there is
108            // a lot of uncertainty.
109            PreDefinedConfigs::AllHistoricalDates => Config::default().with_year(
110                YearConfig::default()
111                    .with_range(1, 3000)
112                    .with_expected(IsExpected::Yes)
113                    .with_two_digit_expansion(TwoDigitYearExpansion::Literal),
114            ),
115
116            // Constrains the year range to the Industrial Revolution period and
117            // uses a sliding window for 2-digit years centred on 1800.
118            // Component order matches Great Britain's common DD/MM/YYYY format.
119            PreDefinedConfigs::IndustrialRevolutionDates => Config::default()
120                .with_year(
121                    YearConfig::default()
122                        .with_range(1760, 1840)
123                        .with_expected(IsExpected::Yes)
124                        .with_two_digit_expansion(TwoDigitYearExpansion::SlidingWindow {
125                            earliest_year: 1750,
126                            pivot: SlidingWindowPivot::new(50),
127                        }),
128                )
129                .with_component_order(
130                    ComponentOrder::new(
131                        DateComponent::Day,
132                        DateComponent::Month,
133                        DateComponent::Year,
134                    )
135                    .unwrap(),
136                ),
137
138            // Children under 18 — birth years must be in the 2000s and not in
139            // the future. Always(Century(2000)) maps all 2-digit values to the
140            // 2000s; the max of 2026 rejects future years.
141            PreDefinedConfigs::ChildrenBirthdays => Config::default().with_year(
142                YearConfig::default()
143                    .with_range(2000, 2026)
144                    .with_expected(IsExpected::Yes)
145                    .with_two_digit_expansion(TwoDigitYearExpansion::Always(Century::new(2000)))
146                    .with_single_digit_expansion(true),
147            ),
148        }
149    }
Source

pub fn with_component_order(self, component_order: ComponentOrder) -> Self

Set the expected ordering of date components for positional inputs.

use partial_date::models::{ComponentOrder, Config, DateComponent};

let config = Config::default().with_component_order(
    ComponentOrder::new(
        DateComponent::Month,
        DateComponent::Day,
        DateComponent::Year,
    )
    .unwrap(),
);
Examples found in repository?
examples/console_entry_config.rs (lines 95-102)
75    pub fn get_config(&self) -> Config {
76        match self {
77            // Strictly day-first numeric dates with all three components
78            // required. Letter-O substitution is disabled since this scenario
79            // expects clean numeric input only.
80            PreDefinedConfigs::StrictDMY => Config::default()
81                .with_day(
82                    DayConfig::default()
83                        .with_expected(IsExpected::Yes),
84                )
85                .with_month(
86                    MonthConfig::default()
87                        .with_expected(IsExpected::Yes)
88                )
89                .with_year(
90                    YearConfig::default()
91                        .with_range(1, 3000)
92                        .with_expected(IsExpected::Yes)
93                        .with_two_digit_expansion(TwoDigitYearExpansion::Literal),
94                )
95                .with_component_order(
96                    ComponentOrder::new(
97                        DateComponent::Day,
98                        DateComponent::Month,
99                        DateComponent::Year,
100                    )
101                    .unwrap(),
102                )
103                .with_letter_o_substitution(false),
104
105            // Wide ranging historical dates that cannot use 2-digit year
106            // expansion as there is no way to know which centuries the dates
107            // will be from. Minimal assumptions about the data when there is
108            // a lot of uncertainty.
109            PreDefinedConfigs::AllHistoricalDates => Config::default().with_year(
110                YearConfig::default()
111                    .with_range(1, 3000)
112                    .with_expected(IsExpected::Yes)
113                    .with_two_digit_expansion(TwoDigitYearExpansion::Literal),
114            ),
115
116            // Constrains the year range to the Industrial Revolution period and
117            // uses a sliding window for 2-digit years centred on 1800.
118            // Component order matches Great Britain's common DD/MM/YYYY format.
119            PreDefinedConfigs::IndustrialRevolutionDates => Config::default()
120                .with_year(
121                    YearConfig::default()
122                        .with_range(1760, 1840)
123                        .with_expected(IsExpected::Yes)
124                        .with_two_digit_expansion(TwoDigitYearExpansion::SlidingWindow {
125                            earliest_year: 1750,
126                            pivot: SlidingWindowPivot::new(50),
127                        }),
128                )
129                .with_component_order(
130                    ComponentOrder::new(
131                        DateComponent::Day,
132                        DateComponent::Month,
133                        DateComponent::Year,
134                    )
135                    .unwrap(),
136                ),
137
138            // Children under 18 — birth years must be in the 2000s and not in
139            // the future. Always(Century(2000)) maps all 2-digit values to the
140            // 2000s; the max of 2026 rejects future years.
141            PreDefinedConfigs::ChildrenBirthdays => Config::default().with_year(
142                YearConfig::default()
143                    .with_range(2000, 2026)
144                    .with_expected(IsExpected::Yes)
145                    .with_two_digit_expansion(TwoDigitYearExpansion::Always(Century::new(2000)))
146                    .with_single_digit_expansion(true),
147            ),
148        }
149    }
Source

pub fn with_no_separator(self, no_separator: bool) -> Self

Enable or disable no-separator parsing (e.g. "25122024").

use partial_date::models::Config;

let config = Config::default().with_no_separator(true);
Source

pub fn with_extra_separators(self, extra_separators: Vec<String>) -> Self

Set additional custom separator strings to try alongside the standard set (/, -, ., ,, \, and whitespace).

use partial_date::models::Config;

let config = Config::default()
    .with_extra_separators(vec!["||".to_string(), " - ".to_string()]);
Source

pub fn with_letter_o_substitution(self, letter_o_substitution: bool) -> Self

Enable or disable substitution of the letter O for the digit 0.

use partial_date::models::Config;

let config = Config::default().with_letter_o_substitution(false);
Examples found in repository?
examples/console_entry_config.rs (line 103)
75    pub fn get_config(&self) -> Config {
76        match self {
77            // Strictly day-first numeric dates with all three components
78            // required. Letter-O substitution is disabled since this scenario
79            // expects clean numeric input only.
80            PreDefinedConfigs::StrictDMY => Config::default()
81                .with_day(
82                    DayConfig::default()
83                        .with_expected(IsExpected::Yes),
84                )
85                .with_month(
86                    MonthConfig::default()
87                        .with_expected(IsExpected::Yes)
88                )
89                .with_year(
90                    YearConfig::default()
91                        .with_range(1, 3000)
92                        .with_expected(IsExpected::Yes)
93                        .with_two_digit_expansion(TwoDigitYearExpansion::Literal),
94                )
95                .with_component_order(
96                    ComponentOrder::new(
97                        DateComponent::Day,
98                        DateComponent::Month,
99                        DateComponent::Year,
100                    )
101                    .unwrap(),
102                )
103                .with_letter_o_substitution(false),
104
105            // Wide ranging historical dates that cannot use 2-digit year
106            // expansion as there is no way to know which centuries the dates
107            // will be from. Minimal assumptions about the data when there is
108            // a lot of uncertainty.
109            PreDefinedConfigs::AllHistoricalDates => Config::default().with_year(
110                YearConfig::default()
111                    .with_range(1, 3000)
112                    .with_expected(IsExpected::Yes)
113                    .with_two_digit_expansion(TwoDigitYearExpansion::Literal),
114            ),
115
116            // Constrains the year range to the Industrial Revolution period and
117            // uses a sliding window for 2-digit years centred on 1800.
118            // Component order matches Great Britain's common DD/MM/YYYY format.
119            PreDefinedConfigs::IndustrialRevolutionDates => Config::default()
120                .with_year(
121                    YearConfig::default()
122                        .with_range(1760, 1840)
123                        .with_expected(IsExpected::Yes)
124                        .with_two_digit_expansion(TwoDigitYearExpansion::SlidingWindow {
125                            earliest_year: 1750,
126                            pivot: SlidingWindowPivot::new(50),
127                        }),
128                )
129                .with_component_order(
130                    ComponentOrder::new(
131                        DateComponent::Day,
132                        DateComponent::Month,
133                        DateComponent::Year,
134                    )
135                    .unwrap(),
136                ),
137
138            // Children under 18 — birth years must be in the 2000s and not in
139            // the future. Always(Century(2000)) maps all 2-digit values to the
140            // 2000s; the max of 2026 rejects future years.
141            PreDefinedConfigs::ChildrenBirthdays => Config::default().with_year(
142                YearConfig::default()
143                    .with_range(2000, 2026)
144                    .with_expected(IsExpected::Yes)
145                    .with_two_digit_expansion(TwoDigitYearExpansion::Always(Century::new(2000)))
146                    .with_single_digit_expansion(true),
147            ),
148        }
149    }

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

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 Config

Source§

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

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

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.