mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-29 10:50:58 +00:00
fix: unify log timestamp offsets (#38904) (thanks @sahilsatralkar)
This commit is contained in:
@@ -117,7 +117,7 @@ describe("logs cli", () => {
|
||||
|
||||
it("formats UTC timestamp in pretty mode", () => {
|
||||
const result = formatLogTimestamp("2025-01-01T12:00:00.000Z", "pretty");
|
||||
expect(result).toBe("12:00:00");
|
||||
expect(result).toBe("12:00:00+00:00");
|
||||
});
|
||||
|
||||
it("formats local time in plain mode when localTime is true", () => {
|
||||
@@ -132,13 +132,8 @@ describe("logs cli", () => {
|
||||
it("formats local time in pretty mode when localTime is true", () => {
|
||||
const utcTime = "2025-01-01T12:00:00.000Z";
|
||||
const result = formatLogTimestamp(utcTime, "pretty", true);
|
||||
// Should be HH:MM:SS format
|
||||
expect(result).toMatch(/^\d{2}:\d{2}:\d{2}$/);
|
||||
// Should be different from UTC time (12:00:00) if not in UTC timezone
|
||||
const tzOffset = new Date(utcTime).getTimezoneOffset();
|
||||
if (tzOffset !== 0) {
|
||||
expect(result).not.toBe("12:00:00");
|
||||
}
|
||||
// Should be HH:MM:SS±HH:MM format with timezone offset.
|
||||
expect(result).toMatch(/^\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}$/);
|
||||
});
|
||||
|
||||
it.each([
|
||||
|
||||
@@ -2,7 +2,7 @@ import { setTimeout as delay } from "node:timers/promises";
|
||||
import type { Command } from "commander";
|
||||
import { buildGatewayConnectionDetails } from "../gateway/call.js";
|
||||
import { parseLogLine } from "../logging/parse-log-line.js";
|
||||
import { formatLocalIsoWithOffset, isValidTimeZone } from "../logging/timestamps.js";
|
||||
import { formatTimestamp, isValidTimeZone } from "../logging/timestamps.js";
|
||||
import { formatDocsLink } from "../terminal/links.js";
|
||||
import { clearActiveProgressLine } from "../terminal/progress-line.js";
|
||||
import { createSafeStreamWriter } from "../terminal/stream-writer.js";
|
||||
@@ -74,16 +74,10 @@ export function formatLogTimestamp(
|
||||
return value;
|
||||
}
|
||||
|
||||
let timeString: string;
|
||||
if (localTime) {
|
||||
timeString = formatLocalIsoWithOffset(parsed);
|
||||
} else {
|
||||
timeString = parsed.toISOString();
|
||||
}
|
||||
if (mode === "pretty") {
|
||||
return timeString.slice(11, 19);
|
||||
return formatTimestamp(parsed, { style: "short", timeZone: localTime ? undefined : "UTC" });
|
||||
}
|
||||
return timeString;
|
||||
return localTime ? formatTimestamp(parsed, { style: "long" }) : parsed.toISOString();
|
||||
}
|
||||
|
||||
function formatLogLine(
|
||||
|
||||
Reference in New Issue
Block a user