From 5ec10f4a359ec49c2f4b8948d4c847102ce96ef0 Mon Sep 17 00:00:00 2001 From: Tom Boullay Date: Sun, 10 May 2026 00:40:26 +0100 Subject: [PATCH] update: gros commit fix editor srt panel 3 --- src/components/editor/EditorSrtPanel.tsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/components/editor/EditorSrtPanel.tsx b/src/components/editor/EditorSrtPanel.tsx index 44d439d..449ca89 100644 --- a/src/components/editor/EditorSrtPanel.tsx +++ b/src/components/editor/EditorSrtPanel.tsx @@ -67,15 +67,19 @@ function createSrtTemplate( } function formatSrtTime(totalSeconds: number): string { - const hours = Math.floor(totalSeconds / 3600); - const minutes = Math.floor((totalSeconds % 3600) / 60); - const seconds = Math.floor(totalSeconds % 60); + const safeSeconds = Math.max(0, totalSeconds); + const totalMilliseconds = Math.round(safeSeconds * 1000); + const milliseconds = totalMilliseconds % 1000; + const totalWholeSeconds = Math.floor(totalMilliseconds / 1000); + const hours = Math.floor(totalWholeSeconds / 3600); + const minutes = Math.floor((totalWholeSeconds % 3600) / 60); + const seconds = totalWholeSeconds % 60; - return `${padTime(hours)}:${padTime(minutes)}:${padTime(seconds)},000`; + return `${padTime(hours)}:${padTime(minutes)}:${padTime(seconds)},${padMilliseconds(milliseconds)}`; } function formatPreviewTime(totalSeconds: number): string { - return `${Math.floor(totalSeconds)}.${Math.floor((totalSeconds % 1) * 10)}s`; + return `${Math.max(0, totalSeconds).toFixed(1)}s`; } function parseSrtTime(value: string): number | null { @@ -97,6 +101,10 @@ function padTime(value: number): string { return value.toString().padStart(2, "0"); } +function padMilliseconds(value: number): string { + return value.toString().padStart(3, "0"); +} + function getSrtDiagnostic( content: string, expectedCueIndexes: number[],