diff --git a/src/lib/format.ts b/src/lib/format.ts index 055eb44..943d822 100644 --- a/src/lib/format.ts +++ b/src/lib/format.ts @@ -5,6 +5,20 @@ export function formatCurrency(amount: number | string | null | undefined) { export function formatDate(value: string | Date | null | undefined) { if (!value) return "—"; + // Date-only strings ("YYYY-MM-DD") must be rendered in UTC, otherwise + // negative-offset timezones show the previous day. + if (typeof value === "string") { + const m = value.match(/^(\d{4})-(\d{2})-(\d{2})$/); + if (m) { + const d = new Date(Date.UTC(+m[1], +m[2] - 1, +m[3])); + return d.toLocaleDateString("en-US", { + year: "numeric", + month: "short", + day: "numeric", + timeZone: "UTC", + }); + } + } const d = typeof value === "string" ? new Date(value) : value; return d.toLocaleDateString("en-US", { year: "numeric", month: "short", day: "numeric" }); }