fix: unify log timestamp offsets (#38904) (thanks @sahilsatralkar)

This commit is contained in:
Ayaan Zaidi
2026-03-25 16:04:27 +05:30
parent 3e2e9bc238
commit ee0dcaa7b0
9 changed files with 103 additions and 44 deletions

View File

@@ -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([

View File

@@ -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(