Skip to content

Commit 0282ef2

Browse files
committed
scale timeline ruler labels to hours
1 parent dc0b57c commit 0282ef2

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

apps/web/src/lib/timeline/ruler-utils.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ const TICK_FRAME_INTERVALS = [1, 2, 3, 5, 10, 15] as const;
1515
/**
1616
* second intervals for when we're zoomed out past frame-level detail.
1717
*/
18-
const SECOND_MULTIPLIERS = [1, 2, 3, 5, 10, 15, 30, 60] as const;
18+
const SECOND_MULTIPLIERS = [
19+
1, 2, 3, 5, 10, 15, 30, 60, 120, 300, 600, 900, 1800, 3600,
20+
] as const;
1921

2022
/**
2123
* minimum pixel spacing between labels to keep them readable
@@ -233,11 +235,20 @@ function getFrameWithinSecond({
233235
}
234236

235237
/**
236-
* formats a timestamp as MM:SS.
238+
* formats a timestamp as MM:SS or H:MM:SS when >= 1 hour.
237239
*/
238240
function formatTimestamp({ timeInSeconds }: { timeInSeconds: number }): string {
239241
const totalSeconds = Math.round(timeInSeconds);
240-
const minutes = Math.floor(totalSeconds / 60);
242+
const hours = Math.floor(totalSeconds / 3600);
243+
const minutes = Math.floor((totalSeconds % 3600) / 60);
241244
const seconds = totalSeconds % 60;
242-
return `${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
245+
246+
const mm = minutes.toString().padStart(2, "0");
247+
const ss = seconds.toString().padStart(2, "0");
248+
249+
if (hours > 0) {
250+
return `${hours}:${mm}:${ss}`;
251+
}
252+
253+
return `${mm}:${ss}`;
243254
}

0 commit comments

Comments
 (0)