This commit is contained in:
Philipinho
2024-05-19 09:06:06 +01:00
parent 9c7c2f1163
commit 6287f41ef6
6 changed files with 22 additions and 20 deletions

View File

@ -1,16 +1,16 @@
import { formatDistanceStrict } from 'date-fns';
import { format, isToday, isYesterday } from 'date-fns';
import { formatDistanceStrict } from "date-fns";
import { format, isToday, isYesterday } from "date-fns";
export function timeAgo(date: Date) {
return formatDistanceStrict(new Date(date), new Date(), { addSuffix: true });
}
export function formatDate(date: Date) {
export function formattedDate(date: Date) {
if (isToday(date)) {
return `Today, ${format(date, 'h:mma')}`;
return `Today, ${format(date, "h:mma")}`;
} else if (isYesterday(date)) {
return `Yesterday, ${format(date, 'h:mma')}`;
return `Yesterday, ${format(date, "h:mma")}`;
} else {
return format(date, 'MMM dd, yyyy, h:mma');
return format(date, "MMM dd, yyyy, h:mma");
}
}