mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-13 13:26:06 +00:00
fix(inbound-meta): include seconds in timestamps
This commit is contained in:
committed by
Peter Steinberger
parent
90f30075aa
commit
4171786f6f
@@ -141,7 +141,7 @@ describe("web auto-reply connection", () => {
|
||||
|
||||
it("handles helper envelope timestamps with trimmed timezones (regression)", () => {
|
||||
const d = new Date("2025-01-01T00:00:00.000Z");
|
||||
expect(formatEnvelopeTimestamp(d, " America/Los_Angeles ")).toBe("Tue 2024-12-31 16:00 PST");
|
||||
expect(formatEnvelopeTimestamp(d, " America/Los_Angeles ")).toBe("Tue 2024-12-31 16:00:00 PST");
|
||||
});
|
||||
|
||||
it("handles reconnect progress and max-attempt stop behavior", async () => {
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
describe("formatAgentEnvelope", () => {
|
||||
it("includes channel, from, ip, host, and timestamp", () => {
|
||||
withEnv({ TZ: "UTC" }, () => {
|
||||
const ts = Date.UTC(2025, 0, 2, 3, 4); // 2025-01-02T03:04:00Z
|
||||
const ts = Date.UTC(2025, 0, 2, 3, 4, 5); // 2025-01-02T03:04:05Z
|
||||
const body = formatAgentEnvelope({
|
||||
channel: "WebChat",
|
||||
from: "user1",
|
||||
@@ -21,7 +21,7 @@ describe("formatAgentEnvelope", () => {
|
||||
body: "hello",
|
||||
});
|
||||
|
||||
expect(body).toBe("[WebChat user1 mac-mini 10.0.0.5 Thu 2025-01-02T03:04Z] hello");
|
||||
expect(body).toBe("[WebChat user1 mac-mini 10.0.0.5 Thu 2025-01-02T03:04:05Z] hello");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -39,7 +39,7 @@ describe("formatAgentEnvelope", () => {
|
||||
|
||||
it("formats timestamps in UTC when configured", () => {
|
||||
withEnv({ TZ: "America/Los_Angeles" }, () => {
|
||||
const ts = Date.UTC(2025, 0, 2, 3, 4); // 2025-01-02T03:04:00Z (19:04 PST)
|
||||
const ts = Date.UTC(2025, 0, 2, 3, 4, 5); // 2025-01-02T03:04:05Z (19:04:05 PST)
|
||||
const body = formatAgentEnvelope({
|
||||
channel: "WebChat",
|
||||
timestamp: ts,
|
||||
@@ -47,12 +47,12 @@ describe("formatAgentEnvelope", () => {
|
||||
body: "hello",
|
||||
});
|
||||
|
||||
expect(body).toBe("[WebChat Thu 2025-01-02T03:04Z] hello");
|
||||
expect(body).toBe("[WebChat Thu 2025-01-02T03:04:05Z] hello");
|
||||
});
|
||||
});
|
||||
|
||||
it("formats timestamps in user timezone when configured", () => {
|
||||
const ts = Date.UTC(2025, 0, 2, 3, 4); // 2025-01-02T03:04:00Z (04:04 CET)
|
||||
const ts = Date.UTC(2025, 0, 2, 3, 4, 5); // 2025-01-02T03:04:05Z (04:04:05 CET)
|
||||
const body = formatAgentEnvelope({
|
||||
channel: "WebChat",
|
||||
timestamp: ts,
|
||||
@@ -60,7 +60,7 @@ describe("formatAgentEnvelope", () => {
|
||||
body: "hello",
|
||||
});
|
||||
|
||||
expect(body).toMatch(/\[WebChat Thu 2025-01-02 04:04 [^\]]+\] hello/);
|
||||
expect(body).toMatch(/\[WebChat Thu 2025-01-02 04:04:05 [^\]]+\] hello/);
|
||||
});
|
||||
|
||||
it("omits timestamps when configured", () => {
|
||||
|
||||
@@ -142,10 +142,10 @@ export function formatEnvelopeTimestamp(
|
||||
|
||||
const formatted =
|
||||
zone.mode === "utc"
|
||||
? formatUtcTimestamp(date)
|
||||
? formatUtcTimestamp(date, { displaySeconds: true })
|
||||
: zone.mode === "local"
|
||||
? formatZonedTimestamp(date)
|
||||
: formatZonedTimestamp(date, { timeZone: zone.timeZone });
|
||||
? formatZonedTimestamp(date, { displaySeconds: true })
|
||||
: formatZonedTimestamp(date, { timeZone: zone.timeZone, displaySeconds: true });
|
||||
|
||||
if (!formatted) {
|
||||
return undefined;
|
||||
|
||||
@@ -27,14 +27,18 @@ export function formatEnvelopeTimestamp(date: Date, zone: EnvelopeTimestampZone
|
||||
})();
|
||||
|
||||
if (normalized === "utc" || normalized === "gmt") {
|
||||
const ts = formatUtcTimestamp(date);
|
||||
const ts = formatUtcTimestamp(date, { displaySeconds: true });
|
||||
return weekday ? `${weekday} ${ts}` : ts;
|
||||
}
|
||||
if (normalized === "local" || normalized === "host") {
|
||||
const ts = formatZonedTimestamp(date) ?? formatUtcTimestamp(date);
|
||||
const ts =
|
||||
formatZonedTimestamp(date, { displaySeconds: true }) ??
|
||||
formatUtcTimestamp(date, { displaySeconds: true });
|
||||
return weekday ? `${weekday} ${ts}` : ts;
|
||||
}
|
||||
const ts = formatZonedTimestamp(date, { timeZone: trimmedZone }) ?? formatUtcTimestamp(date);
|
||||
const ts =
|
||||
formatZonedTimestamp(date, { timeZone: trimmedZone, displaySeconds: true }) ??
|
||||
formatUtcTimestamp(date, { displaySeconds: true });
|
||||
return weekday ? `${weekday} ${ts}` : ts;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user