Files
tkmind_go/ui/desktop/src/utils/timeUtils.ts
T
2025-10-11 10:45:16 -04:00

30 lines
734 B
TypeScript

export function formatMessageTimestamp(timestamp?: number): string {
const date = timestamp ? new Date(timestamp * 1000) : new Date();
const now = new Date();
// Format time as HH:MM AM/PM
const timeStr = date.toLocaleTimeString('en-US', {
hour: 'numeric',
minute: '2-digit',
hour12: true,
});
// Check if the message is from today
if (
date.getDate() === now.getDate() &&
date.getMonth() === now.getMonth() &&
date.getFullYear() === now.getFullYear()
) {
return timeStr;
}
// If not today, format as MM/DD/YYYY HH:MM AM/PM
const dateStr = date.toLocaleDateString('en-US', {
month: '2-digit',
day: '2-digit',
year: 'numeric',
});
return `${dateStr} ${timeStr}`;
}