You've already forked AstralRinth
forked from didirus/AstralRinth
fix: PAT range error guard (#5098)
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user