From 6b006e78e59ac90ef10f81d1ff5bb579a7d34b52 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 22 Jan 2024 22:49:02 +0100 Subject: [PATCH] Improve timer string --- .../ui/src/player/components/left-buttons.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/front/packages/ui/src/player/components/left-buttons.tsx b/front/packages/ui/src/player/components/left-buttons.tsx index 58664037..0b2ff464 100644 --- a/front/packages/ui/src/player/components/left-buttons.tsx +++ b/front/packages/ui/src/player/components/left-buttons.tsx @@ -198,10 +198,15 @@ const ProgressText = (props: Stylable) => { ); }; -const toTimerString = (timer?: number, duration?: number) => { +export const toTimerString = (timer?: number, duration?: number) => { if (!duration) duration = timer; if (timer === undefined || duration === undefined || isNaN(duration) || isNaN(timer)) return "??:??"; - if (duration >= 3600) return new Date(timer * 1000).toISOString().substring(11, 19); - return new Date(timer * 1000).toISOString().substring(14, 19); + const h = Math.floor(timer / 3600); + const min = Math.floor((timer / 60) % 60); + const sec = Math.round(timer % 60); + const fmt = (n: number) => n.toString().padStart(2, "0"); + + if (duration >= 3600) return `${fmt(h)}:${fmt(min)}:${fmt(sec)}`; + return `${fmt(min)}:${fmt(sec)}`; };