🌐 Improve i18n collaboration type and timeSince parsing

This commit is contained in:
Baptiste Arnaud
2023-12-29 11:31:31 +01:00
parent 5124373071
commit f26eafd26f
8 changed files with 116 additions and 66 deletions

View File

@@ -1,30 +0,0 @@
import { TFnType } from '@tolgee/react'
export const parseTimeSince = (t: TFnType, date: string) => {
const seconds = Math.floor(
(new Date().getTime() - new Date(date).getTime()) / 1000
)
let interval = seconds / 31536000
if (interval > 1) {
return t('timeSince.years', { count: Math.floor(interval) })
}
interval = seconds / 2592000
if (interval > 1) {
return t('timeSince.months', { count: Math.floor(interval) })
}
interval = seconds / 86400
if (interval > 1) {
return t('timeSince.days', { count: Math.floor(interval) })
}
interval = seconds / 3600
if (interval > 1) {
return t('timeSince.hours', { count: Math.floor(interval) })
}
interval = seconds / 60
if (interval > 1) {
return t('timeSince.minutes', { count: Math.floor(interval) })
}
return t('timeSince.seconds', { count: Math.floor(interval) })
}