From 70d17d4d5df2794772e0c9ac69462c2f3ec25fc9 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 13 Nov 2021 23:47:39 -0600 Subject: [PATCH] posts: fix incorrect duration shown for certain videos. Fix thumbnails incorrectly showing a duration of "0:00" when a video had a duration between 59.5 seconds and 60.0 seconds. This happened because of incorrect rounding - the seconds value was rounded up, but the minutes value wasn't. Examples: https://danbooru.donmai.us/posts?tags=duration:59.5...60.0+status:any --- app/helpers/application_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9c5ac59ad..10f23b3a0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -103,9 +103,10 @@ module ApplicationHelper end def duration_to_hhmmss(seconds) + seconds = seconds.round hh = seconds.div(1.hour).to_s mm = seconds.div(1.minute).to_s - ss = "%.2d" % (seconds.round % 1.minute) + ss = "%.2d" % (seconds % 1.minute) if seconds >= 1.hour "#{hh}:#{mm}:#{ss}"