import type { Locale } from "./i18n/index.ts"; // SQLite timestamps may arrive as "YYYY-MM-DD HH:MM:SS" (no T/zone); normalize to UTC. function parse(iso: string): Date { return new Date(iso.includes("T") ? iso : `${iso.replace(" ", "T")}Z`); } // Localized date + time (e.g. "5 Jan 2026, 14:03"); falls back to the raw value on parse failure. export function formatDate(iso: string, locale: Locale): string { const d = parse(iso); if (Number.isNaN(d.getTime())) return iso; return d.toLocaleString(locale, { year: "numeric", month: "short", day: "numeric", hour: "2-digit", minute: "2-digit", }); } // Localized date only (e.g. "5 Jan 2026"); falls back to the raw value on parse failure. export function formatDay(iso: string, locale: Locale): string { const d = parse(iso); if (Number.isNaN(d.getTime())) return iso; return d.toLocaleDateString(locale, { year: "numeric", month: "short", day: "numeric", }); }