fix: properly resolve relative date translations

Resolves #798
This commit is contained in:
kolaente 2021-10-04 21:33:20 +02:00
parent 240e8594cc
commit d583cb2094
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 5 additions and 11 deletions

View File

@ -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,
})
}

View File

@ -796,8 +796,6 @@
},
"date": {
"locale": "en",
"in": "in {date}",
"ago": "{date} ago",
"altFormatLong": "j M Y H:i",
"altFormatShort": "j M Y"
},