Show tracks + duration of album, playlist, queue
Stats are in the top right Fixes #475
This commit is contained in:
21
src/utils.rs
Normal file
21
src/utils.rs
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user