You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

29 lines
653 B

import { getDateFnsLocale } from '@ghostfolio/common/helper';
import {
differenceInSeconds,
formatDistanceToNowStrict,
parseISO
} from 'date-fns';
export function formatRelativeTime({
date,
language
}: {
date: Date | string | null | undefined;
language?: string;
}) {
if (date) {
const parsedDate = typeof date === 'string' ? parseISO(date) : date;
const distanceString = formatDistanceToNowStrict(parsedDate, {
addSuffix: true,
locale: getDateFnsLocale(language)
});
return Math.abs(differenceInSeconds(parsedDate, new Date())) < 60
? $localize`just now`
: distanceString;
}
return '';
}