39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
/**
|
|
* Shared date/time formatting utilities for Route Commerce.
|
|
* All dates are stored as TIMESTAMPTZ in PostgreSQL (UTC).
|
|
* Display dates in MM/DD/YYYY format in US locale.
|
|
*/
|
|
|
|
export function formatDate(date: string | Date | null | undefined): string {
|
|
if (!date) return "—";
|
|
const d = typeof date === "string" ? new Date(date) : date;
|
|
if (isNaN(d.getTime())) return "—";
|
|
return d.toLocaleDateString("en-US", {
|
|
month: "2-digit",
|
|
day: "2-digit",
|
|
year: "numeric",
|
|
});
|
|
}
|
|
|
|
export function formatDateTime(date: string | Date | null | undefined): string {
|
|
if (!date) return "—";
|
|
const d = typeof date === "string" ? new Date(date) : date;
|
|
if (isNaN(d.getTime())) return "—";
|
|
return d.toLocaleDateString("en-US", {
|
|
month: "2-digit",
|
|
day: "2-digit",
|
|
year: "numeric",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
});
|
|
}
|
|
|
|
export function formatTime(date: string | Date | null | undefined): string {
|
|
if (!date) return "—";
|
|
const d = typeof date === "string" ? new Date(date) : date;
|
|
if (isNaN(d.getTime())) return "—";
|
|
return d.toLocaleTimeString("en-US", {
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
});
|
|
} |