feat: short time ago
This commit is contained in:
parent
9b207de718
commit
a9af7e4a09
4 changed files with 56 additions and 40 deletions
|
@ -12,28 +12,30 @@ export const useFormattedDateTime = (
|
|||
})
|
||||
}
|
||||
|
||||
export const useTimeAgoOptions = (): UseTimeAgoOptions<false> => {
|
||||
export const useTimeAgoOptions = (short = false): UseTimeAgoOptions<false> => {
|
||||
const { d, t } = useI18n()
|
||||
const prefix = short ? 'short_' : ''
|
||||
|
||||
return {
|
||||
showSecond: true,
|
||||
updateInterval: 1_000,
|
||||
showSecond: !short,
|
||||
updateInterval: short ? 60_000 : 1_000,
|
||||
messages: {
|
||||
justNow: t('time_ago_options.just_now'),
|
||||
// just return the value
|
||||
past: n => n,
|
||||
// just return the value
|
||||
future: n => n,
|
||||
second: (n, p) => t(`time_ago_options.${p ? 'past' : 'future'}_second`, n),
|
||||
minute: (n, p) => t(`time_ago_options.${p ? 'past' : 'future'}_minute`, n),
|
||||
hour: (n, p) => t(`time_ago_options.${p ? 'past' : 'future'}_hour`, n),
|
||||
day: (n, p) => t(`time_ago_options.${p ? 'past' : 'future'}_day`, n),
|
||||
week: (n, p) => t(`time_ago_options.${p ? 'past' : 'future'}_week`, n),
|
||||
month: (n, p) => t(`time_ago_options.${p ? 'past' : 'future'}_month`, n),
|
||||
year: (n, p) => t(`time_ago_options.${p ? 'past' : 'future'}_year`, n),
|
||||
second: (n, p) => t(`time_ago_options.${prefix}second_${p ? 'past' : 'future'}`, n),
|
||||
minute: (n, p) => t(`time_ago_options.${prefix}minute_${p ? 'past' : 'future'}`, n),
|
||||
hour: (n, p) => t(`time_ago_options.${prefix}hour_${p ? 'past' : 'future'}`, n),
|
||||
day: (n, p) => t(`time_ago_options.${prefix}day_${p ? 'past' : 'future'}`, n),
|
||||
week: (n, p) => t(`time_ago_options.${prefix}week_${p ? 'past' : 'future'}`, n),
|
||||
month: (n, p) => t(`time_ago_options.${prefix}month_${p ? 'past' : 'future'}`, n),
|
||||
year: (n, p) => t(`time_ago_options.${prefix}year_${p ? 'past' : 'future'}`, n),
|
||||
},
|
||||
fullDateFormatter(date) {
|
||||
return d(date, 'long')
|
||||
return d(date, short ? 'short' : 'long')
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue