mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 02:50:00 +08:00
19 lines
735 B
TypeScript
19 lines
735 B
TypeScript
/** Time helpers shared by the transcript navigator and the media stage. */
|
|
|
|
export function timeFromSourceHref(value: string): number | null {
|
|
const match = /^#t=(\d+(?:\.\d+)?)$/.exec(value || "");
|
|
if (!match) return null;
|
|
const parsed = Number(match[1]);
|
|
return Number.isFinite(parsed) && parsed >= 0 ? parsed : null;
|
|
}
|
|
|
|
export function formatMediaTime(value: number): string {
|
|
const total = Math.max(0, Math.floor(Number(value) || 0));
|
|
const hours = Math.floor(total / 3600);
|
|
const minutes = Math.floor((total % 3600) / 60);
|
|
const seconds = total % 60;
|
|
return hours
|
|
? `${hours}:${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`
|
|
: `${minutes}:${String(seconds).padStart(2, "0")}`;
|
|
}
|