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
No known key found for this signature in database
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"
},