fix: use local timezone in console log timestamps

formatConsoleTimestamp previously used Date.toISOString() which always
returns UTC time (suffixed with Z). This confused users whose local
timezone differs from UTC.

Now uses local time methods (getHours, getMinutes, etc.) and appends the
local UTC offset (e.g. +08:00) instead of Z. The pretty style returns
local HH:MM:SS. The hasTimestampPrefix regex is updated to accept both
Z and +/-HH:MM offset suffixes.

Closes #14699
This commit is contained in:
Elonito
2026-02-13 00:08:43 +08:00
committed by Peter Steinberger
parent af172742a3
commit 468414cac4
3 changed files with 64 additions and 6 deletions

View File

@@ -86,7 +86,10 @@ describe("enableConsoleCapture", () => {
console.warn("[EventQueue] Slow listener detected");
expect(warn).toHaveBeenCalledTimes(1);
const firstArg = String(warn.mock.calls[0]?.[0] ?? "");
expect(firstArg.startsWith("2026-01-17T18:01:02.000Z [EventQueue]")).toBe(true);
// Timestamp uses local time with timezone offset instead of UTC "Z" suffix
expect(firstArg).toMatch(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}[+-]\d{2}:\d{2} \[EventQueue\]/,
);
vi.useRealTimers();
});