From fbfa0de17ea54b71d69f5df45553be75c47e24b4 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Thu, 8 Feb 2018 20:39:37 +0200 Subject: [PATCH] EpisodeWidget: Fix minutes label parsing. Before if a feed had reported a number between 1 and 60, a label 0 min would be set. This fixes that, while also using chrono::Duration for parsing minutes. --- hammond-gtk/src/widgets/episode.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/hammond-gtk/src/widgets/episode.rs b/hammond-gtk/src/widgets/episode.rs index f4da5a6..0349ed2 100644 --- a/hammond-gtk/src/widgets/episode.rs +++ b/hammond-gtk/src/widgets/episode.rs @@ -4,6 +4,7 @@ use gtk; use chrono::prelude::*; use gtk::prelude::*; +use chrono::Duration; use failure::Error; use humansize::{file_size_opts as size_opts, FileSize}; use open; @@ -187,16 +188,16 @@ impl EpisodeWidget { } /// Set the duration label. - fn set_duration(&self, seconds: Option) { - if (seconds == Some(0)) || seconds.is_none() { - return; - }; - - if let Some(secs) = seconds { - self.duration.set_text(&format!("{} min", secs / 60)); - self.duration.show(); - self.separator1.show(); + fn set_duration(&self, seconds: Option) -> Option<()> { + let minutes = Duration::seconds(seconds?.into()).num_minutes(); + if minutes == 0 { + return None; } + + self.duration.set_text(&format!("{} min", minutes)); + self.duration.show(); + self.separator1.show(); + Some(()) } /// Set the Episode label dependings on its size