feat: add an input so the user can go to a specific timestamp (#530)

* feat: add an input so the user can go to a specific timestamp

* fix: use TimeCode type for EditableTimecodeProps

* cleanup

---------

Co-authored-by: Maze Winther <mazewinther@gmail.com>
This commit is contained in:
Zaka
2025-08-15 23:01:18 +02:00
committed by GitHub
co-authored by Maze Winther
parent 033a9aa1bc
commit 7e4cd76762
11 changed files with 76 additions and 77 deletions
+23 -4
View File
@@ -1,10 +1,14 @@
// Time-related utility functions
import { DEFAULT_FPS } from "@/stores/project-store";
export type TimeCode = "MM:SS" | "HH:MM:SS" | "HH:MM:SS:CS" | "HH:MM:SS:FF";
// Helper function to format time in various formats (MM:SS, HH:MM:SS, HH:MM:SS:CS, HH:MM:SS:FF)
export const formatTimeCode = (
timeInSeconds: number,
format: "MM:SS" | "HH:MM:SS" | "HH:MM:SS:CS" | "HH:MM:SS:FF" = "HH:MM:SS:CS",
fps = 30
format: TimeCode = "HH:MM:SS:CS",
fps = DEFAULT_FPS
): string => {
const hours = Math.floor(timeInSeconds / 3600);
const minutes = Math.floor((timeInSeconds % 3600) / 60);
@@ -26,8 +30,8 @@ export const formatTimeCode = (
export const parseTimeCode = (
timeCode: string,
format: "MM:SS" | "HH:MM:SS" | "HH:MM:SS:CS" | "HH:MM:SS:FF" = "HH:MM:SS:CS",
fps = 30
format: TimeCode = "HH:MM:SS:CS",
fps = DEFAULT_FPS
): number | null => {
if (!timeCode || typeof timeCode !== "string") return null;
@@ -116,3 +120,18 @@ export const parseTimeCode = (
return null;
};
export const guessTimeCodeFormat = (timeCode: string): TimeCode | null => {
if (!timeCode || typeof timeCode !== "string") return null;
const numbers = timeCode.split(":");
if (!numbers.every((n) => !isNaN(Number(n)))) return null;
if (numbers.length === 2) return "MM:SS";
if (numbers.length === 3) return "HH:MM:SS";
// todo: how to tell frames apart from cs?
if (numbers.length === 4) return "HH:MM:SS:FF";
return null;
};