refactor: remove electron-related code

This commit is contained in:
codytseng
2024-12-21 23:20:30 +08:00
parent bed8df06e8
commit 2b1e6fe8f5
200 changed files with 2771 additions and 8432 deletions

View File

@@ -0,0 +1,36 @@
import dayjs from 'dayjs'
import { useTranslation } from 'react-i18next'
export function FormattedTimestamp({
timestamp,
short = false
}: {
timestamp: number
short?: boolean
}) {
const { t } = useTranslation()
const time = dayjs(timestamp * 1000)
const now = dayjs()
const diffMonth = now.diff(time, 'month')
if (diffMonth >= 2) {
return t('date', { timestamp: time.valueOf() })
}
const diffDay = now.diff(time, 'day')
if (diffDay >= 1) {
return short ? t('n d', { n: diffDay }) : t('n days ago', { n: diffDay })
}
const diffHour = now.diff(time, 'hour')
if (diffHour >= 1) {
return short ? t('n h', { n: diffHour }) : t('n hours ago', { n: diffHour })
}
const diffMinute = now.diff(time, 'minute')
if (diffMinute >= 1) {
return short ? t('n m', { n: diffMinute }) : t('n minutes ago', { n: diffMinute })
}
return t('just now')
}