mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-01 10:53:11 +00:00
24 lines
767 B
TypeScript
24 lines
767 B
TypeScript
const AUDIT_DATE_PATTERN = /\b\d{1,2}\/\d{1,2}(\/\d{2,4})?\b/;
|
|
|
|
/**
|
|
* Every entry, manual or system, shows a complete timestamp — `09/15/2026 · 7:42 PM`.
|
|
* Pre-formatted API strings are kept only when they already carry a calendar date.
|
|
*/
|
|
export function formatAuditTimestamp(value: string): string {
|
|
if (!value) return "";
|
|
if (AUDIT_DATE_PATTERN.test(value) && /\b(AM|PM)\b/i.test(value)) return value;
|
|
|
|
const date = new Date(value);
|
|
if (Number.isNaN(date.getTime())) return value;
|
|
|
|
const datePart = date.toLocaleDateString("en-US", {
|
|
month: "2-digit",
|
|
day: "2-digit",
|
|
year: "numeric",
|
|
});
|
|
const timePart = date.toLocaleTimeString("en-US", {
|
|
hour: "numeric",
|
|
minute: "2-digit",
|
|
});
|
|
return `${datePart} · ${timePart}`;
|
|
}
|