From d583cb2094ed3450b2d5437391352058dd8e4b06 Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 4 Oct 2021 21:33:20 +0200 Subject: [PATCH] fix: properly resolve relative date translations Resolves #798 --- src/helpers/time/formatDate.js | 14 +++++--------- src/i18n/lang/en.json | 2 -- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/helpers/time/formatDate.js b/src/helpers/time/formatDate.js index ee5796b6e..89c6a2fc3 100644 --- a/src/helpers/time/formatDate.js +++ b/src/helpers/time/formatDate.js @@ -1,5 +1,5 @@ import {createDateFromString} from '@/helpers/time/createDateFromString' -import {format, formatDistance} from 'date-fns' +import {format, formatDistanceToNow} from 'date-fns' import {enGB, de, fr, ru} from 'date-fns/locale' const locales = {en: enGB, de, ch: de, fr, ru} @@ -29,12 +29,8 @@ export const formatDateSince = (date, $t) => { date = createDateFromString(date) - const currentDate = new Date() - const distance = formatDistance(date, currentDate, {locale: locales[$t('date.locale')]}) - - if (date > currentDate) { - return $t('date.in', {date: distance}) - } - - return $t('date.ago', {date: distance}) + return formatDistanceToNow(date, { + locale: locales[$t('date.locale')], + addSuffix: true, + }) } diff --git a/src/i18n/lang/en.json b/src/i18n/lang/en.json index 7df1566b8..549265b0a 100644 --- a/src/i18n/lang/en.json +++ b/src/i18n/lang/en.json @@ -796,8 +796,6 @@ }, "date": { "locale": "en", - "in": "in {date}", - "ago": "{date} ago", "altFormatLong": "j M Y H:i", "altFormatShort": "j M Y" },