Switch from MM:SS to HH:MM:SS duration representation if needed

* Contidionally switch from MM:SS to HH:MM:SS duration representation if needed.

* Correct tiny style issue.

* --amend
This commit is contained in:
Thomas Frans
2023-02-17 09:22:12 +01:00
committed by GitHub
parent 829b799cc5
commit a3c4989571
5 changed files with 27 additions and 15 deletions

View File

@@ -24,6 +24,25 @@ pub fn format_duration(d: &std::time::Duration) -> String {
s.trim_end().to_string()
}
/// Returns a human readable String of milliseconds in the HH:MM:SS format.
pub fn ms_to_hms(duration: u32) -> String {
let mut formated_time = String::new();
let total_seconds = duration / 1000;
let seconds = total_seconds % 60;
let minutes = (total_seconds / 60) % 60;
let hours = total_seconds / 3600;
if hours > 0 {
formated_time.push_str(&format!("{hours}:{minutes:02}:"));
} else {
formated_time.push_str(&format!("{minutes}:"));
}
formated_time.push_str(&format!("{seconds:02}"));
formated_time
}
pub fn cache_path_for_url(url: String) -> std::path::PathBuf {
let mut path = crate::config::cache_path("covers");
path.push(url.split('/').last().unwrap());