mirror of
https://github.com/docmost/docmost.git
synced 2026-05-13 02:34:05 +08:00
17 lines
490 B
TypeScript
17 lines
490 B
TypeScript
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 formattedDate(date: Date) {
|
|
if (isToday(date)) {
|
|
return `Today, ${format(date, "h:mma")}`;
|
|
} else if (isYesterday(date)) {
|
|
return `Yesterday, ${format(date, "h:mma")}`;
|
|
} else {
|
|
return format(date, "MMM dd, yyyy, h:mma");
|
|
}
|
|
}
|