Skip to content

Commit 32c445b

Browse files
authored
improvement: better time formatting for clip track (#1005)
* Update ClipTrack.tsx * Update ClipTrack.tsx
1 parent d9c4961 commit 32c445b

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

apps/desktop/src/routes/editor/Timeline/ClipTrack.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ import {
2929
useSegmentWidth,
3030
} from "./Track";
3131

32+
function formatTime(totalSeconds: number): string {
33+
const hours = Math.floor(totalSeconds / 3600);
34+
const minutes = Math.floor((totalSeconds % 3600) / 60);
35+
const seconds = Math.floor(totalSeconds % 60);
36+
37+
if (hours > 0) {
38+
return `${hours}h ${minutes}m ${seconds}s`;
39+
} else if (minutes > 0) {
40+
return `${minutes}m ${seconds}s`;
41+
} else {
42+
return `${seconds}s`;
43+
}
44+
}
45+
3246
function WaveformCanvas(props: {
3347
systemWaveform?: number[];
3448
micWaveform?: number[];
@@ -468,7 +482,7 @@ export function ClipTrack(
468482
</span>
469483
<div class="flex gap-1 items-center text-md dark:text-gray-12 text-gray-1">
470484
<IconLucideClock class="size-3.5" />{" "}
471-
{(segment.end - segment.start).toFixed(1)}s
485+
{formatTime(segment.end - segment.start)}
472486
</div>
473487
</div>
474488
</Show>
@@ -627,21 +641,18 @@ function CutOffsetButton(props: {
627641
class?: string;
628642
onClick?(): void;
629643
}) {
630-
const formatTime = (t: number) =>
631-
t < 1 ? Math.round(t * 10) / 10 : Math.round(t);
632-
633644
return (
634645
<button
635646
class={cx(
636-
"h-7 bg-red-300 hover:bg-red-400 text-xs tabular-nums text-white p-2 flex flex-row items-center transition-colors",
647+
"h-7 bg-red-300 text-nowrap hover:bg-red-400 text-xs tabular-nums text-white p-2 flex flex-row items-center transition-colors",
637648
props.class,
638649
)}
639650
onClick={() => props.onClick?.()}
640651
>
641652
{props.value === 0 ? (
642653
<IconCapScissors class="size-3.5" />
643654
) : (
644-
<>{formatTime(props.value)}s</>
655+
<>{formatTime(props.value)}</>
645656
)}
646657
</button>
647658
);

0 commit comments

Comments
 (0)