mirror of
https://github.com/OpenCut-app/OpenCut.git
synced 2026-07-13 21:52:53 +02:00
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:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user