yap-blog/src/lib/format.ts
2026-07-02 21:32:33 -04:00

16 lines
494 B
TypeScript

// Fixed locale and UTC keep server-rendered dates deterministic
// (no hydration mismatches, no test flakiness across machines).
const dateFormatter = new Intl.DateTimeFormat("en-US", {
dateStyle: "long",
timeZone: "UTC",
});
export function formatDate(date: Date | null | undefined): string {
if (!date) return "—";
return dateFormatter.format(date);
}
export function isoDate(date: Date | null | undefined): string | undefined {
return date ? date.toISOString() : undefined;
}