fix: PAT range error guard (#5098)

This commit is contained in:
Calum H.
2026-01-16 03:30:00 +00:00
committed by GitHub
parent 4ee7623837
commit 75c5316dc3

View File

@@ -2,7 +2,7 @@ import { computed, type ComputedRef } from 'vue'
import { injectI18n } from '../providers/i18n' 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 { export interface FormatOptions {
roundingMode?: 'halfExpand' | 'floor' | 'ceil' roundingMode?: 'halfExpand' | 'floor' | 'ceil'
@@ -25,8 +25,16 @@ export function useRelativeTime(): Formatter {
formatters.set(locale.value, formatterRef) 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) const date = value instanceof Date ? value : new Date(value)
if (Number.isNaN(date.getTime())) {
return ''
}
const now = Date.now() const now = Date.now()
const diff = date.getTime() - now const diff = date.getTime() - now