feat(api): user-scoped CSV export matching legacy format

This commit is contained in:
Bas van Rossem
2026-06-17 15:49:20 +02:00
parent b067bb65b0
commit 85184d3287
3 changed files with 214 additions and 1 deletions

13
apps/api/src/lib/csv.ts Normal file
View File

@@ -0,0 +1,13 @@
// CSV helpers ported verbatim from the legacy export route (docs/reference/legacy-backend.md §4).
// Wrap a value in double quotes, doubling any embedded double quote (standard CSV escaping).
export const quote = (value: unknown) => `"${String(value).replace(/"/g, '""')}"`;
// Format a total number of seconds as zero-padded HH:MM:SS (hours can exceed 99).
export function formatDuration(totalSeconds: number): string {
const s = totalSeconds || 0;
const h = Math.floor(s / 3600);
const m = Math.floor((s % 3600) / 60);
const sec = s % 60;
return `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}:${String(sec).padStart(2, '0')}`;
}