feat: scaffold Tauri v2 + Svelte 5 project with base layout and utilities
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
36
src/lib/utils/time.ts
Normal file
36
src/lib/utils/time.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
export function formatTime(totalSeconds: number): string {
|
||||
const hours = Math.floor(totalSeconds / 3600);
|
||||
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||
const seconds = Math.floor(totalSeconds % 60);
|
||||
const millis = Math.round((totalSeconds % 1) * 1000);
|
||||
|
||||
const mm = String(minutes).padStart(2, '0');
|
||||
const ss = String(seconds).padStart(2, '0');
|
||||
const ms = String(millis).padStart(3, '0');
|
||||
|
||||
if (hours > 0) {
|
||||
return `${hours}:${mm}:${ss}.${ms}`;
|
||||
}
|
||||
return `${mm}:${ss}.${ms}`;
|
||||
}
|
||||
|
||||
export function parseTime(str: string): number | null {
|
||||
const hmsMatch = str.match(/^(\d+):(\d{2}):(\d{2})(?:\.(\d{1,3}))?$/);
|
||||
if (hmsMatch) {
|
||||
const h = parseInt(hmsMatch[1], 10);
|
||||
const m = parseInt(hmsMatch[2], 10);
|
||||
const s = parseInt(hmsMatch[3], 10);
|
||||
const ms = hmsMatch[4] ? parseInt(hmsMatch[4].padEnd(3, '0'), 10) : 0;
|
||||
return h * 3600 + m * 60 + s + ms / 1000;
|
||||
}
|
||||
|
||||
const msMatch = str.match(/^(\d{2}):(\d{2})(?:\.(\d{1,3}))?$/);
|
||||
if (msMatch) {
|
||||
const m = parseInt(msMatch[1], 10);
|
||||
const s = parseInt(msMatch[2], 10);
|
||||
const ms = msMatch[3] ? parseInt(msMatch[3].padEnd(3, '0'), 10) : 0;
|
||||
return m * 60 + s + ms / 1000;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user