feat: replace timeago with dayjs
This commit is contained in:
@@ -1,34 +1,13 @@
|
||||
import { format, register } from 'timeago.js';
|
||||
import dayjs from 'dayjs';
|
||||
import relativeTime from 'dayjs/plugin/relativeTime';
|
||||
|
||||
const TimeAgoConfiguration: string[][] = [
|
||||
['today', 'today'],
|
||||
['%s seconds ago', 'in %s seconds'],
|
||||
['1 minute ago', 'in 1 minute'],
|
||||
['%s minutes ago', 'in %s minutes'],
|
||||
['1 hour ago', 'in 1 hour'],
|
||||
['%s hours ago', 'in %s hours'],
|
||||
['1 day ago', 'in 1 day'],
|
||||
['%s days ago', 'in %s days'],
|
||||
['1 week ago', 'in 1 week'],
|
||||
['%s weeks ago', 'in %s weeks'],
|
||||
['1 month ago', 'in 1 month'],
|
||||
['%s months ago', 'in %s months'],
|
||||
['1 year ago', 'in 1 year'],
|
||||
['%s years ago', 'in %s years'],
|
||||
];
|
||||
dayjs.extend(relativeTime);
|
||||
|
||||
function timeago(date?: Date): string {
|
||||
function formatFromNow(date: Date | null): string {
|
||||
if (!date) {
|
||||
return 'today';
|
||||
return 'none';
|
||||
}
|
||||
|
||||
const localeFunc = (number: number, index: number, _?: number): [string, string] => {
|
||||
return TimeAgoConfiguration[index] as [string, string];
|
||||
};
|
||||
|
||||
register('timeago', localeFunc);
|
||||
|
||||
return format(date, 'timeago');
|
||||
return dayjs(date).fromNow()
|
||||
}
|
||||
|
||||
function formatDate(date: Date): string {
|
||||
@@ -46,4 +25,4 @@ function formatShortDate(date: Date): string {
|
||||
})
|
||||
}
|
||||
|
||||
export { formatDate, formatShortDate, timeago };
|
||||
export { formatFromNow, formatDate, formatShortDate, };
|
||||
|
||||
Reference in New Issue
Block a user