pub struct ComponentOrder {
pub first: DateComponent,
pub second: DateComponent,
pub third: DateComponent,
}Expand description
The expected ordering of date components in positional (numeric) input.
For example, 01/06/24 is ambiguous — a ComponentOrder of
[Day, Month, Year] interprets it as 1 June 2024, while
[Month, Day, Year] gives 6 January 2024.
For unambiguous inputs (e.g. 31/06/24) the correct interpretation
can always be determined regardless of this setting.
All three components must be present and each must appear exactly once.
Construct with ComponentOrder::new to enforce this invariant, or use
ComponentOrder::default for the standard Day/Month/Year order.
Fields§
§first: DateComponentThe component expected in the first position.
second: DateComponentThe component expected in the second position.
third: DateComponentThe component expected in the third position.
Implementations§
Source§impl ComponentOrder
impl ComponentOrder
Sourcepub fn new(
first: DateComponent,
second: DateComponent,
third: DateComponent,
) -> Result<Self, ComponentOrderError>
pub fn new( first: DateComponent, second: DateComponent, third: DateComponent, ) -> Result<Self, ComponentOrderError>
Create a new ComponentOrder, returning Err if any component is
duplicated (which also implies another is missing).
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 }Trait Implementations§
Source§impl Clone for ComponentOrder
impl Clone for ComponentOrder
Source§fn clone(&self) -> ComponentOrder
fn clone(&self) -> ComponentOrder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more