diff --git a/packages/ui/src/composables/how-ago.ts b/packages/ui/src/composables/how-ago.ts index bf1182ba..6d86df93 100644 --- a/packages/ui/src/composables/how-ago.ts +++ b/packages/ui/src/composables/how-ago.ts @@ -2,7 +2,7 @@ import { computed, type ComputedRef } from 'vue' import { injectI18n } from '../providers/i18n' -export type Formatter = (value: Date | number, options?: FormatOptions) => string +export type Formatter = (value: Date | number | null | undefined, options?: FormatOptions) => string export interface FormatOptions { roundingMode?: 'halfExpand' | 'floor' | 'ceil' @@ -25,8 +25,16 @@ export function useRelativeTime(): Formatter { formatters.set(locale.value, formatterRef) } - return (value: Date | number) => { + return (value: Date | number | null | undefined) => { + if (value == null) { + return '' + } + const date = value instanceof Date ? value : new Date(value) + + if (Number.isNaN(date.getTime())) { + return '' + } const now = Date.now() const diff = date.getTime() - now