forked from janek/mostr
1
0
Fork 0

fix(tasks): time display format replacements

This commit is contained in:
xeruf 2024-08-02 11:13:36 +03:00
parent bf802e3195
commit 9619435c03
1 changed files with 6 additions and 1 deletions

View File

@ -579,13 +579,18 @@ impl Tasks {
} }
} }
/// Formats the given seconds according to the given format.
/// MMM - minutes
/// MM - minutes of the hour
/// HH - hours
/// Returns an empty string if under a minute.
fn display_time(format: &str, secs: u64) -> String { fn display_time(format: &str, secs: u64) -> String {
Some(secs / 60) Some(secs / 60)
.filter(|t| t > &0) .filter(|t| t > &0)
.map_or(String::new(), |mins| format .map_or(String::new(), |mins| format
.replace("MMM", &format!("{:3}", mins))
.replace("HH", &format!("{:02}", mins.div(60))) .replace("HH", &format!("{:02}", mins.div(60)))
.replace("MM", &format!("{:02}", mins.rem(60))) .replace("MM", &format!("{:02}", mins.rem(60)))
.replace("MMM", &format!("{:3}", mins)),
) )
} }