From 2ac75b126d216c038ab9ef965af9925251142fe1 Mon Sep 17 00:00:00 2001 From: Sam Davies Date: Fri, 16 Aug 2024 13:52:37 +0100 Subject: [PATCH] WEB-7281: Tidying timestamps into just minutes and seconds --- app/server/public/javascript/timestamps.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/server/public/javascript/timestamps.js b/app/server/public/javascript/timestamps.js index 7b34625..659c13b 100644 --- a/app/server/public/javascript/timestamps.js +++ b/app/server/public/javascript/timestamps.js @@ -1,7 +1,23 @@ window.addEventListener('DOMContentLoaded', (event) => { + const parseTimestamp = (tsString) => { + const parsed = tsString.split(':').map((t) => Number(t)).reverse(); + return { + hours: parsed[2] || 0, + minutes: parsed[1] || 0, + seconds: parsed[0] || 0, + }; + }; + + const displayTime = (tsString) => { + const time = parseTimestamp(tsString); + const mins = `${time.hours * 60 + time.minutes}`.padStart(2, '0'); + const secs = time.seconds.toFixed(0).toString().padStart(2, '0'); + return `${mins}:${secs}`; + }; + const elements = document.querySelectorAll('span[data-video-timestamp]'); [...elements].forEach((element) => { - element.classList.add('o-badge', 'o-badge-product--highlight', 'video-timestamp'); - element.innerHTML = element.dataset.videoTimestamp; + element.classList.add('video-timestamp'); + element.innerHTML = displayTime(element.dataset.videoTimestamp); }); });