Skip to content

Commit 78ab09a

Browse files
committed
fix(terminal-line): improve timestamp formatting and validation in log parsing
1 parent 754d5c0 commit 78ab09a

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

dashboard/src/components/nodes/terminal-line.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export function TerminalLine({ log, noTimestamp, searchTerm }: LogLineProps) {
2020
const { t, i18n } = useTranslation()
2121
const locale = i18n.language
2222

23-
const formattedTime = timestamp
24-
? timestamp.toLocaleTimeString([], {
23+
const formattedTime = timestamp && !isNaN(timestamp.getTime())
24+
? timestamp.toLocaleTimeString(locale || undefined, {
2525
hour: '2-digit',
2626
minute: '2-digit',
2727
second: '2-digit',

dashboard/src/utils/logsUtils.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,21 @@ export function parseLogs(logString: string): LogLine[] {
5959

6060
let parsedTimestamp: Date | null = null
6161
if (timestamp) {
62-
// Handle Xray format: 2025/09/27 13:26:58.279079 (assume UTC)
63-
if (timestamp.includes('/')) {
64-
parsedTimestamp = new Date(timestamp + 'Z') // Treat as UTC
65-
} else {
66-
// Handle other formats
67-
parsedTimestamp = new Date(timestamp.replace(' UTC', 'Z'))
62+
try {
63+
// Handle Xray format: 2025/09/27 13:26:58.279079 (assume UTC)
64+
if (timestamp.includes('/')) {
65+
parsedTimestamp = new Date(timestamp + 'Z') // Treat as UTC
66+
} else {
67+
// Handle other formats
68+
parsedTimestamp = new Date(timestamp.replace(' UTC', 'Z'))
69+
}
70+
// Validate the parsed date is valid
71+
if (isNaN(parsedTimestamp.getTime())) {
72+
parsedTimestamp = null
73+
}
74+
} catch {
75+
// If date parsing fails, set to null
76+
parsedTimestamp = null
6877
}
6978
}
7079

0 commit comments

Comments
 (0)