1
0
Fork 0

Remove pageState in formatDistance.ts.

This commit is contained in:
Kitteh 2021-05-15 10:58:54 +01:00
parent 89bedc8be5
commit 4e390d3e96
2 changed files with 5 additions and 6 deletions

View file

@ -1,8 +1,7 @@
import { de, enGB, fr, it, nl, ru } from "date-fns/locale";
import { formatDistance as formatDistanceReal } from "date-fns";
import { pageState } from "./globalPageState";
function getLocale(): Locale {
function getLocale(language: string): Locale {
return {
en: enGB,
fr: fr,
@ -10,9 +9,9 @@ function getLocale(): Locale {
ru: ru,
de: de,
it: it,
}[pageState.language];
}[language];
}
export function formatDistance(d1: Date, d2: Date): string {
return formatDistanceReal(d1, d2, { locale: getLocale() });
export function formatDistance(d1: Date, d2: Date, language: string): string {
return formatDistanceReal(d1, d2, { locale: getLocale(language) });
}

View file

@ -118,7 +118,7 @@ document.addEventListener(
interpolation: {
format: function (value: unknown, format, _): string {
if (format === "until_date" && value instanceof Date)
return formatDistance(new Date(), new Date(value));
return formatDistance(new Date(), new Date(value), pageState.language);
return value as string;
},
},