@@ -3,6 +3,8 @@ import { escapeRegExp } from 'lodash'
33import { Badge } from '@/components/ui/badge'
44import { Tooltip , TooltipContent , TooltipPortal , TooltipProvider , TooltipTrigger } from '@/components/ui/tooltip'
55import { cn } from '@/lib/utils'
6+ import dayjs from '@/lib/dayjs'
7+ import type { Dayjs } from 'dayjs'
68import { getLogType , type LogLine } from '@/utils/logsUtils'
79import { useTranslation } from 'react-i18next'
810
@@ -20,15 +22,28 @@ export function TerminalLine({ log, noTimestamp, searchTerm }: LogLineProps) {
2022 const { t, i18n } = useTranslation ( )
2123 const locale = i18n . language
2224
23- const formattedTime =
24- timestamp && ! isNaN ( timestamp . getTime ( ) )
25- ? timestamp . toLocaleTimeString ( locale || undefined , {
26- hour : '2-digit' ,
27- minute : '2-digit' ,
28- second : '2-digit' ,
29- hour12 : false ,
30- } )
31- : ''
25+ const parseLogDayjs = ( value : Date | string | null ) : Dayjs | null => {
26+ if ( ! value ) return null
27+ if ( value instanceof Date ) {
28+ return isNaN ( value . getTime ( ) ) ? null : dayjs ( value )
29+ }
30+
31+ const cleaned = value . includes ( ' UTC' ) ? value . replace ( ' UTC' , 'Z' ) : value
32+ const formats = [ 'YYYY/MM/DD HH:mm:ss.SSSSSS' , 'YYYY/MM/DD HH:mm:ss.SSS' , 'YYYY/MM/DD HH:mm:ss' , 'YYYY-MM-DD HH:mm:ss.SSS' , 'YYYY-MM-DD HH:mm:ss' ]
33+
34+ for ( const format of formats ) {
35+ const parsed = dayjs . utc ( cleaned , format , true )
36+ if ( parsed . isValid ( ) ) return parsed . local ( )
37+ }
38+
39+ const fallback = dayjs . utc ( cleaned )
40+ return fallback . isValid ( ) ? fallback . local ( ) : null
41+ }
42+
43+ const parsedDate = parseLogDayjs ( timestamp ) ?? parseLogDayjs ( rawTimestamp )
44+
45+ const displayTime = parsedDate ? parsedDate . format ( 'HH:mm:ss' ) : rawTimestamp || ''
46+ const tooltipTimestamp = parsedDate ? parsedDate . format ( 'YYYY-MM-DD HH:mm:ss' ) : rawTimestamp || ''
3247
3348 const highlightMessage = ( text : string , term : string ) => {
3449 if ( ! term ) {
@@ -83,11 +98,13 @@ export function TerminalLine({ log, noTimestamp, searchTerm }: LogLineProps) {
8398 : 'hover:bg-gray-200/50 dark:hover:bg-gray-800/50' ,
8499 ) }
85100 >
86- < div className = " flex flex-shrink-0 items-start gap-2" >
101+ < div className = { cn ( ' flex flex-shrink-0 items-start gap-2' , noTimestamp && 'gap-1' ) } >
87102 { /* Icon to expand the log item maybe implement a colapsible later */ }
88103 { /* <Square className="size-4 text-muted-foreground opacity-0 group-hover/logitem:opacity-100 transition-opacity" /> */ }
89- { tooltip ( color , rawTimestamp ) }
90- { ! noTimestamp && < span className = "w-14 flex-shrink-0 select-none text-[11px] text-muted-foreground sm:w-20 sm:text-xs" > { formattedTime } </ span > }
104+ { tooltip ( color , tooltipTimestamp || null ) }
105+ { ! noTimestamp && (
106+ < span className = "w-20 flex-shrink-0 select-text text-[11px] text-muted-foreground sm:w-24 sm:text-xs" > { displayTime } </ span >
107+ ) }
91108
92109 < Badge variant = { variant } className = { cn ( 'w-12 flex-shrink-0 justify-center px-1 py-0 text-[11px] sm:w-14 sm:text-[10px]' , locale === 'fa' && 'font-body' ) } >
93110 { t ( `nodes.logs.${ type } ` ) }
0 commit comments