Something went wrong. Try again.
🌿 Collaborative wiki on ATProto
Something went wrong. Try again.
941 B · 30 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031import 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", });}