Skip to content

Commit 6e6b14d

Browse files
committed
Simplify defaults
1 parent 6a04862 commit 6e6b14d

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/util/aggregators/date.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,28 @@ impl Aggregator for Date {
9292
/// Resets the aggregator to its initial state, preserving `format` and `parser_type`.
9393
fn reset(&mut self) {
9494
self.count = 0;
95-
self.earliest = match self.parser_type {
96-
DateParserType::Date => DateTime::new(Dt::MAX, Tm::MIDNIGHT),
97-
DateParserType::Time => DateTime::new(Dt::MIN, Tm::from_hms(23, 59, 59).unwrap()),
98-
DateParserType::DateTime => DateTime::new(Dt::MAX, Tm::MIDNIGHT),
99-
};
100-
self.latest = match self.parser_type {
101-
DateParserType::Date => DateTime::new(Dt::MIN, Tm::MIDNIGHT),
102-
DateParserType::Time => DateTime::new(Dt::MIN, Tm::MIDNIGHT),
103-
DateParserType::DateTime => DateTime::new(Dt::MIN, Tm::MIDNIGHT),
104-
};
95+
let (earliest, latest) = Self::default_datetimes(&self.parser_type);
96+
self.earliest = earliest;
97+
self.latest = latest;
10598
}
10699
}
107100

108101
impl Date {
109102
/// Constructs a new `Date` aggregator with the given `format` and `parser_type`.
110103
pub fn new(format: &str, parser_type: DateParserType) -> Self {
111-
let (earliest, latest) = match parser_type {
104+
let (earliest, latest) = Self::default_datetimes(&parser_type);
105+
106+
Self {
107+
format: parse_owned::<2>(format).ok(),
108+
earliest,
109+
latest,
110+
count: 0,
111+
parser_type,
112+
}
113+
}
114+
115+
fn default_datetimes(parser_type: &DateParserType) -> (DateTime, DateTime) {
116+
match parser_type {
112117
DateParserType::Date => (
113118
DateTime::new(Dt::MAX, Tm::MIDNIGHT),
114119
DateTime::new(Dt::MIN, Tm::MIDNIGHT),
@@ -121,14 +126,6 @@ impl Date {
121126
DateTime::new(Dt::MAX, Tm::MIDNIGHT),
122127
DateTime::new(Dt::MIN, Tm::MIDNIGHT),
123128
),
124-
};
125-
126-
Self {
127-
format: parse_owned::<2>(format).ok(),
128-
earliest,
129-
latest,
130-
count: 0,
131-
parser_type,
132129
}
133130
}
134131

0 commit comments

Comments
 (0)