fix: standardize relative timestamping (#3612)

* fix(frontend): relative timestamps are incorrectly rounded.

Closes: #1371

* fix(all): remove legacy fromNow for proper relative timestamp creation

Closes: #1395
This commit is contained in:
Calum H.
2025-05-07 22:37:35 +01:00
committed by GitHub
parent 6d57da2053
commit 1884410e0d
33 changed files with 233 additions and 150 deletions

View File

@@ -0,0 +1,23 @@
import { createFormatter, type FormatOptions, type Formatter } from '@vintl/how-ago'
import type { IntlController } from '@vintl/vintl/controller'
import { useVIntl } from '@vintl/vintl'
import { computed } from 'vue'
/* eslint-disable @typescript-eslint/no-explicit-any */
const formatters = new WeakMap<IntlController<any>, Formatter>()
export function useRelativeTime(): Formatter {
const vintl = useVIntl()
let formatter = formatters.get(vintl)
if (formatter == null) {
const formatterRef = computed(() => createFormatter(vintl.intl))
const defaultOptions: FormatOptions = { roundingMode: 'halfExpand' as const }
formatter = (value, options) => formatterRef.value(value, { ...options, ...defaultOptions })
formatters.set(vintl, formatter)
}
return formatter
}

View File

@@ -0,0 +1 @@
export * from './how-ago'