Remove pageState in formatDistance.ts.
This commit is contained in:
parent
89bedc8be5
commit
4e390d3e96
|
@ -1,8 +1,7 @@
|
||||||
import { de, enGB, fr, it, nl, ru } from "date-fns/locale";
|
import { de, enGB, fr, it, nl, ru } from "date-fns/locale";
|
||||||
import { formatDistance as formatDistanceReal } from "date-fns";
|
import { formatDistance as formatDistanceReal } from "date-fns";
|
||||||
import { pageState } from "./globalPageState";
|
|
||||||
|
|
||||||
function getLocale(): Locale {
|
function getLocale(language: string): Locale {
|
||||||
return {
|
return {
|
||||||
en: enGB,
|
en: enGB,
|
||||||
fr: fr,
|
fr: fr,
|
||||||
|
@ -10,9 +9,9 @@ function getLocale(): Locale {
|
||||||
ru: ru,
|
ru: ru,
|
||||||
de: de,
|
de: de,
|
||||||
it: it,
|
it: it,
|
||||||
}[pageState.language];
|
}[language];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatDistance(d1: Date, d2: Date): string {
|
export function formatDistance(d1: Date, d2: Date, language: string): string {
|
||||||
return formatDistanceReal(d1, d2, { locale: getLocale() });
|
return formatDistanceReal(d1, d2, { locale: getLocale(language) });
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,7 @@ document.addEventListener(
|
||||||
interpolation: {
|
interpolation: {
|
||||||
format: function (value: unknown, format, _): string {
|
format: function (value: unknown, format, _): string {
|
||||||
if (format === "until_date" && value instanceof Date)
|
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;
|
return value as string;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue