20 lines
715 B
TypeScript
20 lines
715 B
TypeScript
/**
|
|
* Journal date display. `occurredAt` is an in-world *calendar day* stored as UTC
|
|
* midnight, and the `createdAt` fallback is a UTC instant; both are rendered in
|
|
* UTC so a machine behind UTC never shows the previous day. Pure and
|
|
* deterministic (independent of the server/browser timezone).
|
|
*/
|
|
|
|
const UTC_DATE_FORMAT = new Intl.DateTimeFormat("en-US", {
|
|
year: "numeric",
|
|
month: "long",
|
|
day: "numeric",
|
|
timeZone: "UTC",
|
|
});
|
|
|
|
export function formatJournalDate(value: string | Date | null | undefined): string | null {
|
|
if (!value) return null;
|
|
const date = value instanceof Date ? value : new Date(value);
|
|
if (Number.isNaN(date.getTime())) return null;
|
|
return UTC_DATE_FORMAT.format(date);
|
|
}
|