Fixed ledger date parsing
X-Lovable-Edit-ID: edt-f1cb902c-3a0e-4f4d-b857-f66da196ebba Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
@@ -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" });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user