🐛 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() {
|
if !self.retention.is_empty() {
|
||||||
let count = &self.retention[2..];
|
let count = &self.retention[2..];
|
||||||
let count = count.parse::<usize>().unwrap();
|
let count = count.parse::<usize>().unwrap();
|
||||||
let period = match self.retention.chars().nth(0) {
|
let mut period = match self.retention.chars().nth(0) {
|
||||||
Some('d') => {
|
Some('d') => "day",
|
||||||
if count == 1 {
|
Some('w') => "week",
|
||||||
"day"
|
Some('m') => "month",
|
||||||
} else {
|
Some('y') => "year",
|
||||||
"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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(_) => unreachable!(),
|
Some(_) => unreachable!(),
|
||||||
None => unreachable!(),
|
None => unreachable!(),
|
||||||
};
|
}
|
||||||
|
.to_string();
|
||||||
|
if count > 1 {
|
||||||
|
period.push('s');
|
||||||
|
}
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"Rule #{} is active on {} and applies when the message is {count} {period} old.",
|
"Rule #{} is active on {} and applies when the message is {count} {period} old.",
|
||||||
|
|||||||
Reference in New Issue
Block a user