🐛 fix(config): correct pluralization of time periods in EolRule display
- fix pluralization logic for day, week, month, and year - avoid redundant match arms by pushing 's' when count > 1
This commit is contained in:
committed by
Jeremiah Russell
parent
739f7e69f5
commit
6b1dedc10a
@@ -19,38 +19,18 @@ impl fmt::Display for EolRule {
|
||||
if !self.retention.is_empty() {
|
||||
let count = &self.retention[2..];
|
||||
let count = count.parse::<usize>().unwrap();
|
||||
let period = match self.retention.chars().nth(0) {
|
||||
Some('d') => {
|
||||
if count == 1 {
|
||||
"day"
|
||||
} else {
|
||||
"days"
|
||||
}
|
||||
}
|
||||
Some('w') => {
|
||||
if count == 1 {
|
||||
"week"
|
||||
} else {
|
||||
"weeks"
|
||||
}
|
||||
}
|
||||
Some('m') => {
|
||||
if count == 1 {
|
||||
"month"
|
||||
} else {
|
||||
"months"
|
||||
}
|
||||
}
|
||||
Some('y') => {
|
||||
if count == 1 {
|
||||
"year"
|
||||
} else {
|
||||
"years"
|
||||
}
|
||||
}
|
||||
let mut period = match self.retention.chars().nth(0) {
|
||||
Some('d') => "day",
|
||||
Some('w') => "week",
|
||||
Some('m') => "month",
|
||||
Some('y') => "year",
|
||||
Some(_) => unreachable!(),
|
||||
None => unreachable!(),
|
||||
};
|
||||
}
|
||||
.to_string();
|
||||
if count > 1 {
|
||||
period.push('s');
|
||||
}
|
||||
write!(
|
||||
f,
|
||||
"Rule #{} is active on {} and applies when the message is {count} {period} old.",
|
||||
|
||||
Reference in New Issue
Block a user