mirror of
https://github.com/docmost/docmost.git
synced 2026-05-12 01:41:12 +08:00
17 lines
487 B
TypeScript
17 lines
487 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 formatDate(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');
|
|
}
|
|
}
|