From 4e390d3e96f46e3b5fc220e22a07c0b2d9232e07 Mon Sep 17 00:00:00 2001 From: Kitteh Date: Sat, 15 May 2021 10:58:54 +0100 Subject: [PATCH] Remove pageState in formatDistance.ts. --- src/formatDistance.ts | 9 ++++----- src/main.ts | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/formatDistance.ts b/src/formatDistance.ts index 2893af8..26071ee 100644 --- a/src/formatDistance.ts +++ b/src/formatDistance.ts @@ -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) }); } diff --git a/src/main.ts b/src/main.ts index 2867e2b..fd10dae 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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; }, },