13 lines
550 B
TypeScript
13 lines
550 B
TypeScript
/**
|
|
* Backend timestamps are SQLite UTC-naive strings ("2026-09-28 01:44:28").
|
|
* `Date.parse` treats those as LOCAL time, shifting every elapsed/duration
|
|
* computation by the local UTC offset. Parse them as UTC instead; strings
|
|
* that already carry a timezone marker pass through unchanged.
|
|
*/
|
|
export function parseDbTs(raw: string | null | undefined): number {
|
|
if (!raw) return NaN;
|
|
const s = raw.trim();
|
|
if (/[zZ]$|[+-]\d{2}:?\d{2}$/.test(s)) return Date.parse(s);
|
|
return Date.parse(s.endsWith("Z") ? s : `${s.replace(" ", "T")}Z`);
|
|
}
|