From 2bdd20906cac74e9dcb8afc80e63d621c246c7e8 Mon Sep 17 00:00:00 2001 From: discollizard Date: Fri, 24 Nov 2023 08:11:22 -0300 Subject: [PATCH] abbreviated length logic abstracted into a helper function --- src/invidious/helpers/utils.cr | 16 ++++++++++++++++ src/invidious/views/watch.ecr | 12 +----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index 500a2582..7aa15899 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -11,6 +11,22 @@ def ci_lower_bound(pos, n) return (phat + z*z/(2*n) - z * Math.sqrt((phat*(1 - phat) + z*z/(4*n))/n))/(1 + z*z/n) end +def video_length_abbreviated(length) + length_abbreviated = "" + if length.days > 0 + length_abbreviated = "#{length.days} d #{length.hours} hr #{length.minutes} min" + elsif length.hours > 0 + length_abbreviated = "#{length.hours} h #{length.minutes} min" + elsif length.minutes > 0 + length_abbreviated = "#{length.minutes} min" + else + length_abbreviated = "#{length.seconds} seconds" + end + + return length_abbreviated + +end + def elapsed_text(elapsed) millis = elapsed.total_milliseconds return "#{millis.round(2)}ms" if millis >= 1 diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index a75a321c..b1e72b00 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -77,17 +77,7 @@ we're going to need to do it here in order to allow for translations.

<%= title %> - <% time_span_length = video.length_seconds.seconds %> - - <% if time_span_length.days > 0 %> - <%= time_span_length.days %> d <%= time_span_length.hours %> hr <%= time_span_length.minutes %> min - <% elsif time_span_length.hours > 0 %> - <%= time_span_length.hours %> hr <%= time_span_length.minutes %> min - <% elsif time_span_length.minutes > 0 %> - <%= time_span_length.minutes %> min - <% else %> - <%= time_span_length.seconds %> seconds - <% end %> + <%= video_length_abbreviated(video.length_seconds.seconds)%> <% if params.listen %> " href="/watch?<%= env.params.query %>&listen=0">