2021-05-12 16:01:04 +01:00
|
|
|
import { de, enGB, fr, it, nl, ru } from "date-fns/locale";
|
|
|
|
import { formatDistance as formatDistanceReal } from "date-fns";
|
2021-04-24 18:42:13 +01:00
|
|
|
|
2021-05-15 10:58:54 +01:00
|
|
|
function getLocale(language: string): Locale {
|
2021-04-24 18:42:13 +01:00
|
|
|
return {
|
2021-05-12 16:01:04 +01:00
|
|
|
en: enGB,
|
|
|
|
fr: fr,
|
|
|
|
nl: nl,
|
|
|
|
ru: ru,
|
|
|
|
de: de,
|
|
|
|
it: it,
|
2021-05-15 10:58:54 +01:00
|
|
|
}[language];
|
2021-04-24 18:42:13 +01:00
|
|
|
}
|
|
|
|
|
2021-05-15 10:58:54 +01:00
|
|
|
export function formatDistance(d1: Date, d2: Date, language: string): string {
|
|
|
|
return formatDistanceReal(d1, d2, { locale: getLocale(language) });
|
2021-05-12 16:01:04 +01:00
|
|
|
}
|