Skip to content

Commit 75c5316

Browse files
authored
fix: PAT range error guard (#5098)
1 parent 4ee7623 commit 75c5316

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/ui/src/composables/how-ago.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { computed, type ComputedRef } from 'vue'
22

33
import { injectI18n } from '../providers/i18n'
44

5-
export type Formatter = (value: Date | number, options?: FormatOptions) => string
5+
export type Formatter = (value: Date | number | null | undefined, options?: FormatOptions) => string
66

77
export interface FormatOptions {
88
roundingMode?: 'halfExpand' | 'floor' | 'ceil'
@@ -25,8 +25,16 @@ export function useRelativeTime(): Formatter {
2525
formatters.set(locale.value, formatterRef)
2626
}
2727

28-
return (value: Date | number) => {
28+
return (value: Date | number | null | undefined) => {
29+
if (value == null) {
30+
return ''
31+
}
32+
2933
const date = value instanceof Date ? value : new Date(value)
34+
35+
if (Number.isNaN(date.getTime())) {
36+
return ''
37+
}
3038
const now = Date.now()
3139
const diff = date.getTime() - now
3240

0 commit comments

Comments
 (0)