Skip to content

Commit

Permalink
WEB-7281: Tidying timestamps into just minutes and seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
sammyd committed Aug 16, 2024
1 parent cb8b394 commit 2ac75b1
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions app/server/public/javascript/timestamps.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 2ac75b1

Please sign in to comment.