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:
19
src/utils.rs
19
src/utils.rs
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user