diff --git a/web/src/pages/app/mods/StatusBar/LogsModal/index.tsx b/web/src/pages/app/mods/StatusBar/LogsModal/index.tsx index 74db0a6..eeb8d17 100644 --- a/web/src/pages/app/mods/StatusBar/LogsModal/index.tsx +++ b/web/src/pages/app/mods/StatusBar/LogsModal/index.tsx @@ -38,17 +38,40 @@ type Log = { const MAX_RETRIES = 5; -const timestampRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/; +// eslint-disable-next-line no-control-regex +const timestampRegex = /\u001b\[90m(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z)/g; +// const timestampRegex = new RegExp( +// "\\u001b\\[90m(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z)", +// "g", +// ); -function convertLogTimestamp(log: Log): Log { - const match = log.data.match(timestampRegex); +function formatToCustomDateString(date: Date): string { + const pad = (num: number) => String(num).padStart(2, "0"); + const padMillis = (num: number) => String(num).padStart(3, "0"); + + const year = date.getFullYear(); + const month = pad(date.getMonth() + 1); // Months are zero-indexed + const day = pad(date.getDate()); + const hours = pad(date.getHours()); + const minutes = pad(date.getMinutes()); + const seconds = pad(date.getSeconds()); + const milliseconds = padMillis(date.getMilliseconds()); + + const timeZoneOffset = -date.getTimezoneOffset(); + const offsetHours = pad(Math.floor(Math.abs(timeZoneOffset) / 60)); + const offsetMinutes = pad(Math.abs(timeZoneOffset) % 60); + const offsetSign = timeZoneOffset >= 0 ? "+" : "-"; + const timeZone = `T${hours}:${minutes}:${seconds}.${milliseconds}${offsetSign}${offsetHours}:${offsetMinutes}`; - if (match) { - const timestamp = match[0]; - const date = new Date(timestamp); - const clientTimeString = date.toString(); - log.data = log.data.replace(timestamp, clientTimeString); - } + return `${year}-${month}-${day}${timeZone}`; +} + +function convertLogTimestamp(log: Log): Log { + log.data = log.data.replace(timestampRegex, (match, p1) => { + const date = new Date(p1); + const clientTimeString = formatToCustomDateString(date); // 将时间转换为带时区的客户端时间字符串 + return `\u001b[90m${clientTimeString}`; + }); return log; }