tweak duration formatting in logs

This commit is contained in:
Armaël Guéneau 2024-04-15 23:14:32 +02:00
parent 84adeddec6
commit 8bc9126264

View file

@ -89,15 +89,17 @@ impl fmt::Display for AlertStatus {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let days = |d: Duration| d.as_secs() / (3600 * 24);
let hours = |d: Duration| (d.as_secs() / 3600) % 24;
let minutes = |d: Duration| (d.as_secs() / 60) % 60;
write!(
f,
"{}: inactivity: {} days, {} hours, last_alert: {}",
"{}: inactivity: {}d{}h{}m, last_alert: {}",
(if self.alert { "ALERT" } else { "no alert" }),
days(self.inactivity),
hours(self.inactivity),
minutes(self.inactivity),
match self.last_alert {
None => "none".to_owned(),
Some(d) => format!("{} days, {} hours", days(d), hours(d)),
Some(d) => format!("{}d{}h{}m", days(d), hours(d), minutes(d)),
}
)
}