feat: short time ago
This commit is contained in:
parent
9b207de718
commit
a9af7e4a09
|
@ -41,7 +41,7 @@ function go(evt: MouseEvent | KeyboardEvent) {
|
|||
}
|
||||
|
||||
const createdAt = useFormattedDateTime(status.createdAt)
|
||||
const timeAgoOptions = useTimeAgoOptions()
|
||||
const timeAgoOptions = useTimeAgoOptions(true)
|
||||
const timeago = useTimeAgo(() => status.createdAt, timeAgoOptions)
|
||||
</script>
|
||||
|
||||
|
|
|
@ -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')
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -142,20 +142,34 @@
|
|||
},
|
||||
"time_ago_options": {
|
||||
"just_now": "just now",
|
||||
"past_second": "just now|{n} second ago|{n} seconds ago",
|
||||
"future_second": "just now|in {n} second|in {n} seconds",
|
||||
"past_minute": "0 minutes ago|1 minute ago|{n} minutes ago",
|
||||
"future_minute": "in 0 minutes|in 1 minute|in {n} minutes",
|
||||
"past_hour": "0 hours ago|1 hour ago|{n} hours ago",
|
||||
"future_hour": "in 0 hours|in 1 hour|in {n} hours",
|
||||
"past_day": "0 days ago|yesterday|{n} days ago",
|
||||
"future_day": "in 0 days|tomorrow|in {n} days",
|
||||
"past_week": "0 weeks ago|last week|{n} weeks ago",
|
||||
"future_week": "in 0 weeks|next week|in {n} weeks",
|
||||
"past_month": "0 months ago|last month|{n} months ago",
|
||||
"future_month": "in 0 months|next month|in {n} months",
|
||||
"past_year": "0 years ago|last year|{n} years ago",
|
||||
"future_year": "in 0 years|next year|in {n} years"
|
||||
"second_past": "just now|{n} second ago|{n} seconds ago",
|
||||
"second_future": "just now|in {n} second|in {n} seconds",
|
||||
"minute_past": "0 minutes ago|1 minute ago|{n} minutes ago",
|
||||
"minute_future": "in 0 minutes|in 1 minute|in {n} minutes",
|
||||
"hour_past": "0 hours ago|1 hour ago|{n} hours ago",
|
||||
"hour_future": "in 0 hours|in 1 hour|in {n} hours",
|
||||
"day_past": "0 days ago|yesterday|{n} days ago",
|
||||
"day_future": "in 0 days|tomorrow|in {n} days",
|
||||
"week_past": "0 weeks ago|last week|{n} weeks ago",
|
||||
"week_future": "in 0 weeks|next week|in {n} weeks",
|
||||
"month_past": "0 months ago|last month|{n} months ago",
|
||||
"month_future": "in 0 months|next month|in {n} months",
|
||||
"year_past": "0 years ago|last year|{n} years ago",
|
||||
"year_future": "in 0 years|next year|in {n} years",
|
||||
"short_second_past": "{n}s",
|
||||
"short_second_future": "in {n}s",
|
||||
"short_minute_past": "{n}min",
|
||||
"short_minute_future": "in {n}min",
|
||||
"short_hour_past": "{n}h",
|
||||
"short_hour_future": "in {n}h",
|
||||
"short_day_past": "{n}d",
|
||||
"short_day_future": "in {n}d",
|
||||
"short_week_past": "{n}w",
|
||||
"short_week_future": "in {n}w",
|
||||
"short_month_past": "{n}mo",
|
||||
"short_month_future": "in {n}mo",
|
||||
"short_year_past": "{n}y",
|
||||
"short_year_future": "in {n}y"
|
||||
},
|
||||
"timeline": {
|
||||
"show_new_items": "Show {n} new items"
|
||||
|
|
|
@ -126,20 +126,20 @@
|
|||
},
|
||||
"time_ago_options": {
|
||||
"just_now": "ahora mismo",
|
||||
"past_second": "hace 0 segundos|hace {n} segundo|hace {n} segundos",
|
||||
"future_second": "dentro de 0 segundos|dentro de {n} segundo|dentro de {n} segundos",
|
||||
"past_minute": "hace 0 minutos|hace 1 minuto|hace {n} minutos",
|
||||
"future_minute": "dentro de 0 minutos|dentro de 1 minuto|dentro de {n} minutos",
|
||||
"past_hour": "hace 0 horas|hace 1 hora|hace {n} horas",
|
||||
"future_hour": "dentro de 0 horas|dentro de 1 hora|dentro {n} horas",
|
||||
"past_day": "hace 0 días|ayer|hace {n} días",
|
||||
"future_day": "dentro de 0 días|mañana|dentro de {n} días",
|
||||
"past_week": "hace 0 semanas|la semana pasada|hace {n} semanas",
|
||||
"future_week": "dentro de 0 semanas|la próxima semana|dentro de {n} semanas",
|
||||
"past_month": "hace 0 meses|el mes pasado|hace {n} meses",
|
||||
"future_month": "dentro de 0 meses|el próximo mes|dentro de {n} meses",
|
||||
"past_year": "hace 0 años|el año pasado|hace {n} años",
|
||||
"future_year": "dentro de 0 años|el próximo año|dentro de {n} años",
|
||||
"second_past": "hace 0 segundos|hace {n} segundo|hace {n} segundos",
|
||||
"second_future": "dentro de 0 segundos|dentro de {n} segundo|dentro de {n} segundos",
|
||||
"minute_past": "hace 0 minutos|hace 1 minuto|hace {n} minutos",
|
||||
"minute_future": "dentro de 0 minutos|dentro de 1 minuto|dentro de {n} minutos",
|
||||
"hour_past": "hace 0 horas|hace 1 hora|hace {n} horas",
|
||||
"hour_future": "dentro de 0 horas|dentro de 1 hora|dentro {n} horas",
|
||||
"day_past": "hace 0 días|ayer|hace {n} días",
|
||||
"day_future": "dentro de 0 días|mañana|dentro de {n} días",
|
||||
"week_past": "hace 0 semanas|la semana pasada|hace {n} semanas",
|
||||
"week_future": "dentro de 0 semanas|la próxima semana|dentro de {n} semanas",
|
||||
"month_past": "hace 0 meses|el mes pasado|hace {n} meses",
|
||||
"month_future": "dentro de 0 meses|el próximo mes|dentro de {n} meses",
|
||||
"year_past": "hace 0 años|el año pasado|hace {n} años",
|
||||
"year_future": "dentro de 0 años|el próximo año|dentro de {n} años",
|
||||
"tomorrow": "mañana",
|
||||
"yesterday": "ayer"
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue