Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/ui/src/composables/how-ago.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { computed, type ComputedRef } from 'vue'
import { useI18n } from 'vue-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'
Expand All @@ -24,8 +24,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

Expand Down