owncast/web/components/chat/ChatUserMessage/messageFmt.ts

18 lines
456 B
TypeScript
Raw Normal View History

import { getDiffInDaysFromNow } from '../../../utils/helpers';
export function formatTimestamp(sentAt: Date) {
const now = new Date(sentAt);
if (Number.isNaN(now)) return '';
const diffInDays = getDiffInDaysFromNow(sentAt);
if (diffInDays >= 1) {
const localeDate = now.toLocaleDateString('en-US', {
dateStyle: 'medium',
});
return `${localeDate} at ${now.toLocaleTimeString()}`;
}
return `${now.toLocaleTimeString()}`;
}