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

@@ -2,6 +2,7 @@ use crate::library::Library;
use crate::model::playable::Playable;
use crate::queue::Queue;
use crate::traits::{ListItem, ViewExt};
use crate::utils::ms_to_hms;
use chrono::{DateTime, Utc};
use rspotify::model::show::{FullEpisode, SimplifiedEpisode};
use rspotify::model::Id;
@@ -23,9 +24,7 @@ pub struct Episode {
impl Episode {
pub fn duration_str(&self) -> String {
let minutes = self.duration / 60_000;
let seconds = (self.duration / 1000) % 60;
format!("{minutes:02}:{seconds:02}")
ms_to_hms(self.duration)
}
}

View File

@@ -8,6 +8,7 @@ use crate::model::episode::Episode;
use crate::model::track::Track;
use crate::queue::Queue;
use crate::traits::{ListItem, ViewExt};
use crate::utils::ms_to_hms;
use std::fmt;
use std::sync::Arc;
@@ -118,10 +119,7 @@ impl Playable {
}
pub fn duration_str(&self) -> String {
let duration = self.duration();
let minutes = duration / 60_000;
let seconds = (duration / 1000) % 60;
format!("{minutes:02}:{seconds:02}")
ms_to_hms(self.duration())
}
pub fn as_listitem(&self) -> Box<dyn ListItem> {

View File

@@ -2,6 +2,7 @@ use std::fmt;
use std::sync::{Arc, RwLock};
use crate::config;
use crate::utils::ms_to_hms;
use chrono::{DateTime, Utc};
use rspotify::model::album::FullAlbum;
use rspotify::model::track::{FullTrack, SavedTrack, SimplifiedTrack};
@@ -72,9 +73,7 @@ impl Track {
}
pub fn duration_str(&self) -> String {
let minutes = self.duration / 60_000;
let seconds = (self.duration / 1000) % 60;
format!("{minutes:02}:{seconds:02}")
ms_to_hms(self.duration)
}
}