From bfa159a1bf0c3a0dc2e4b507008ed4b66726b510 Mon Sep 17 00:00:00 2001 From: Deimos Date: Wed, 13 Feb 2019 21:45:36 -0700 Subject: [PATCH] Fix duration display for less than 1 minute Previously, a video 30 seconds long would have just displayed its duration as "30". This fixes it to "0:30". --- tildes/tildes/models/topic/topic.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tildes/tildes/models/topic/topic.py b/tildes/tildes/models/topic/topic.py index d4d56a9..cec0870 100644 --- a/tildes/tildes/models/topic/topic.py +++ b/tildes/tildes/models/topic/topic.py @@ -392,7 +392,15 @@ class Topic(DatabaseModel): duration = self.get_content_metadata("duration") if duration: duration_delta = timedelta(seconds=duration) - metadata_strings.append(str(duration_delta).lstrip("0:")) + + # When converted to str, timedelta always includes hours and minutes, + # so we want to strip off all the excess zeros and/or colons. However, + # if it's less than a minute we'll need to add one back. + duration_str = str(duration_delta).lstrip("0:") + if duration < 60: + duration_str = f"0:{duration_str}" + + metadata_strings.append(duration_str) # display the published date if it's more than 3 days before the topic published_timestamp = self.get_content_metadata("published")