Show tracks + duration of album, playlist, queue

Stats are in the top right

Fixes #475
This commit is contained in:
Henrik Friedrichsen
2021-04-08 22:13:07 +02:00
parent 577e7ebd87
commit 32cb6e70d3
7 changed files with 83 additions and 0 deletions

21
src/utils.rs Normal file
View File

@@ -0,0 +1,21 @@
/// Returns a human readable String of a Duration
///
/// Example: `3h 12m 53s`
pub fn format_duration(d: &std::time::Duration) -> String {
let mut s = String::new();
let mut append_unit = |value, unit| {
if value > 0 {
s.push_str(&format!("{}{}", value, unit));
}
};
let seconds = d.as_secs() % 60;
let minutes = (d.as_secs() / 60) % 60;
let hours = (d.as_secs() / 60) / 60;
append_unit(hours, "h ");
append_unit(minutes, "m ");
append_unit(seconds, "s ");
s.trim_end().to_string()
}