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.
 
 
 
 
 

28 lines
562 B

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