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: DayConfigConfiguration for day extraction.
month: MonthConfigConfiguration for month extraction.
year: YearConfigConfiguration for year extraction.
component_order: ComponentOrderThe expected ordering of date components for positional (numeric) inputs.
Default: Day → Month → Year. See ComponentOrder.
no_separator: boolWhen 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: boolWhen 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
impl Config
Sourcepub fn with_day(self, day: DayConfig) -> Self
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?
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 }Sourcepub fn with_month(self, month: MonthConfig) -> Self
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?
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 }Sourcepub fn with_year(self, year: YearConfig) -> Self
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?
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 }Sourcepub fn with_component_order(self, component_order: ComponentOrder) -> Self
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?
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 }Sourcepub fn with_no_separator(self, no_separator: bool) -> Self
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);Sourcepub fn with_extra_separators(self, extra_separators: Vec<String>) -> Self
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()]);Sourcepub fn with_letter_o_substitution(self, letter_o_substitution: bool) -> Self
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?
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 }