fix console log time and server card layout
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { formatTerminalLogTime } from "./logTime";
|
||||
|
||||
describe("formatTerminalLogTime", () => {
|
||||
it("uses the SCUM log clock instead of the browser timezone", () => {
|
||||
expect(formatTerminalLogTime("2026-08-24T01:23:44Z", "[2026.08.23-17.23.44][418]LogSCUM: Global Stats"))
|
||||
.toBe("17:23:44");
|
||||
});
|
||||
|
||||
it("falls back to the event timestamp for generic logs", () => {
|
||||
expect(formatTerminalLogTime("not-a-timestamp")).toBe("时间未知");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
const scumLogTimestampPattern = /\[?(\d{4})\.(\d{2})\.(\d{2})-(\d{2})\.(\d{2})\.(\d{2})(?:[.:]\d{1,3})?\]?/;
|
||||
|
||||
export function formatTerminalLogTime(timestamp: string, line?: string): string {
|
||||
const embedded = line?.match(scumLogTimestampPattern);
|
||||
if (embedded) {
|
||||
return `${embedded[4]}:${embedded[5]}:${embedded[6]}`;
|
||||
}
|
||||
|
||||
const date = new Date(timestamp);
|
||||
return Number.isNaN(date.getTime()) ? "时间未知" : date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", second: "2-digit" });
|
||||
}
|
||||
Reference in New Issue
Block a user