2022-05-24 08:47:22 +02:00
|
|
|
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',
|
|
|
|
});
|
2022-11-18 17:08:46 -08:00
|
|
|
return `${localeDate} at ${now.toLocaleTimeString()}`;
|
2022-05-24 08:47:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return `${now.toLocaleTimeString()}`;
|
|
|
|
}
|