-
Notifications
You must be signed in to change notification settings - Fork 1.2k
improvement: better time formatting for clip track #1005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -29,6 +29,20 @@ import { | |||||||||
| useSegmentWidth, | ||||||||||
| } from "./Track"; | ||||||||||
|
|
||||||||||
| function formatTime(totalSeconds: number): string { | ||||||||||
| const hours = Math.floor(totalSeconds / 3600); | ||||||||||
| const minutes = Math.floor((totalSeconds % 3600) / 60); | ||||||||||
| const seconds = Math.floor(totalSeconds % 60); | ||||||||||
|
|
||||||||||
| if (hours > 0) { | ||||||||||
| return `${hours}h ${minutes}m ${seconds}s`; | ||||||||||
| } else if (minutes > 0) { | ||||||||||
| return `${minutes}m ${seconds}s`; | ||||||||||
| } else { | ||||||||||
| return `${seconds}s`; | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| function WaveformCanvas(props: { | ||||||||||
| systemWaveform?: number[]; | ||||||||||
| micWaveform?: number[]; | ||||||||||
|
|
@@ -468,7 +482,7 @@ export function ClipTrack( | |||||||||
| </span> | ||||||||||
| <div class="flex gap-1 items-center text-md dark:text-gray-12 text-gray-1"> | ||||||||||
| <IconLucideClock class="size-3.5" />{" "} | ||||||||||
| {(segment.end - segment.start).toFixed(1)}s | ||||||||||
| {formatTime(segment.end - segment.start)} | ||||||||||
| </div> | ||||||||||
| </div> | ||||||||||
| </Show> | ||||||||||
|
|
@@ -627,21 +641,18 @@ function CutOffsetButton(props: { | |||||||||
| class?: string; | ||||||||||
| onClick?(): void; | ||||||||||
| }) { | ||||||||||
| const formatTime = (t: number) => | ||||||||||
| t < 1 ? Math.round(t * 10) / 10 : Math.round(t); | ||||||||||
|
|
||||||||||
| return ( | ||||||||||
| <button | ||||||||||
| class={cx( | ||||||||||
| "h-7 bg-red-300 hover:bg-red-400 text-xs tabular-nums text-white p-2 flex flex-row items-center transition-colors", | ||||||||||
| "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", | ||||||||||
| props.class, | ||||||||||
| )} | ||||||||||
| onClick={() => props.onClick?.()} | ||||||||||
| > | ||||||||||
| {props.value === 0 ? ( | ||||||||||
| <IconCapScissors class="size-3.5" /> | ||||||||||
| ) : ( | ||||||||||
| <>{formatTime(props.value)}s</> | ||||||||||
| <>{formatTime(props.value)}</> | ||||||||||
| )} | ||||||||||
|
Comment on lines
+655
to
656
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Update call site to the renamed formatter. Aligns with the improved duration formatting and sub-second handling. - <>{formatTime(props.value)}</>
+ <>{formatDuration(props.value)}</>📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| </button> | ||||||||||
| ); | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Fix sub-second rounding and avoid name collision with existing utils.formatTime.
Current logic floors everything (e.g., 0.4s -> "0s"), which is misleading in CutOffsetButton and a UX regression from the prior 0.1s precision. Also, naming this helper formatTime collides conceptually with apps/desktop/src/routes/editor/utils.ts:formatTime (mm:ss[.ff]) and can confuse future readers.
Suggested: rename and improve formatting to preserve tenths under 10s, handle negatives, and keep integer seconds when minutes/hours are present.
Follow-up: consider centralizing this in editor/utils as a separate humanizer (e.g., humanizeDuration) to avoid two different “formatTime” semantics.
🏁 Script executed:
Length of output: 22669
Fix sub-second rounding and rename local formatTime to avoid collision
📝 Committable suggestion
🤖 Prompt for AI Agents