mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-03 17:53:14 +00:00
25 lines
775 B
TypeScript
25 lines
775 B
TypeScript
|
|
const AUDIT_DATE_PATTERN = /\b\d{1,2}\/\d{1,2}(\/\d{2,4})?\b/;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* SH-361: 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}`;
|
||
|
|
}
|