refactor: Enhance health-related components by integrating date formatting for last checked timestamps and improving tooltip display, ensuring better readability and user experience
Build, Test, and Push CFDM Docker Image / test (push) Successful in 4m0s
Build, Test, and Push CFDM Docker Image / build-and-push (push) Successful in 2m5s
Build, Test, and Push CFDM Docker Image / update-wiki (push) Successful in 7s
Build, Test, and Push CFDM Docker Image / create-release (push) Has been skipped

This commit is contained in:
Denozordec
2026-06-25 23:12:20 +07:00
parent 5bdf4e774d
commit 934afa5c95
7 changed files with 59 additions and 26 deletions
+15 -1
View File
@@ -5,9 +5,23 @@ const dateFormatter = new Intl.DateTimeFormat('ru-RU', {
const relativeFormatter = new Intl.RelativeTimeFormat('ru', { numeric: 'auto' })
/**
* SQLite `datetime('now')` возвращает UTC в формате `YYYY-MM-DD HH:MM:SS` без суффикса `Z`.
* `new Date(...)` парсит такую строку как локальное время — отображение уезжает на TZ-сдвиг.
* Конвертируем в полноценный ISO с `Z`, чтобы `new Date(...)` трактовал время как UTC.
*/
export function sqliteUtcToIso(value: string | null | undefined): string | null {
if (!value) return null
const trimmed = value.trim()
if (trimmed.endsWith('Z') || /[+-]\d{2}:?\d{2}$/.test(trimmed)) return trimmed
const match = /^(\d{4}-\d{2}-\d{2})[ T](\d{2}:\d{2}:\d{2})/.exec(trimmed)
if (!match) return trimmed
return `${match[1]}T${match[2]}Z`
}
export function formatDate(iso: string | null | undefined): string {
if (!iso) return '—'
const date = new Date(iso)
const date = new Date(sqliteUtcToIso(iso) ?? iso)
if (Number.isNaN(date.getTime())) return iso
return dateFormatter.format(date)
}
+4 -2
View File
@@ -1,5 +1,6 @@
import { useQuery } from '@tanstack/react-query'
import { healthStatusQueryOptions } from '@/queries'
import { sqliteUtcToIso } from '@/lib/format'
import type { IpHealthStatus } from '@/lib/schemas'
export type HealthScope = 'binding' | 'group'
@@ -60,8 +61,9 @@ export function aggregateHealth(rows: IpHealthStatus[]): AggregatedHealth {
}
}
if (row.last_checked_at) {
if (!lastCheckedAt || row.last_checked_at > lastCheckedAt) {
lastCheckedAt = row.last_checked_at
const iso = sqliteUtcToIso(row.last_checked_at) ?? row.last_checked_at
if (!lastCheckedAt || iso > lastCheckedAt) {
lastCheckedAt = iso
}
}
if (row.last_error && !lastError) lastError = row.last_error