feat: add bgp observability and admin ui improvements
This commit is contained in:
47
frontend/src/utils/datetime.ts
Normal file
47
frontend/src/utils/datetime.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
export function parseBackendDate(value: string | null | undefined): Date | null {
|
||||
if (!value) return null
|
||||
|
||||
let normalized = value.trim()
|
||||
if (!normalized) return null
|
||||
|
||||
if (normalized.includes(' ') && !normalized.includes('T')) {
|
||||
normalized = normalized.replace(' ', 'T')
|
||||
}
|
||||
|
||||
const hasTimezone = /(?:Z|[+-]\d{2}:\d{2})$/.test(normalized)
|
||||
if (!hasTimezone) {
|
||||
normalized = `${normalized}Z`
|
||||
}
|
||||
|
||||
const date = new Date(normalized)
|
||||
return Number.isNaN(date.getTime()) ? null : date
|
||||
}
|
||||
|
||||
function padNumber(value: number): string {
|
||||
return String(value).padStart(2, '0')
|
||||
}
|
||||
|
||||
export function formatDateTimeZhCN(value: string | null | undefined): string {
|
||||
const date = parseBackendDate(value)
|
||||
if (!date) return '-'
|
||||
|
||||
const year = date.getFullYear()
|
||||
const month = padNumber(date.getMonth() + 1)
|
||||
const day = padNumber(date.getDate())
|
||||
const hours = padNumber(date.getHours())
|
||||
const minutes = padNumber(date.getMinutes())
|
||||
const seconds = padNumber(date.getSeconds())
|
||||
|
||||
return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`
|
||||
}
|
||||
|
||||
export function formatDateZhCN(value: string | null | undefined): string {
|
||||
const date = parseBackendDate(value)
|
||||
if (!date) return '-'
|
||||
|
||||
const year = date.getFullYear()
|
||||
const month = padNumber(date.getMonth() + 1)
|
||||
const day = padNumber(date.getDate())
|
||||
|
||||
return `${year}/${month}/${day}`
|
||||
}
|
||||
Reference in New Issue
Block a user