mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 21:24:31 +00:00
feat: append UTC time alongside local time in shared Current time lines (#32423)
Merged via squash.
Prepared head SHA: 9e8ec13933
Co-authored-by: jriff <50276+jriff@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
This commit is contained in:
@@ -25,7 +25,8 @@ export function resolveCronStyleNow(cfg: TimeConfigLike, nowMs: number): CronSty
|
||||
const userTimeFormat = resolveUserTimeFormat(cfg.agents?.defaults?.timeFormat);
|
||||
const formattedTime =
|
||||
formatUserTime(new Date(nowMs), userTimezone, userTimeFormat) ?? new Date(nowMs).toISOString();
|
||||
const timeLine = `Current time: ${formattedTime} (${userTimezone})`;
|
||||
const utcTime = new Date(nowMs).toISOString().replace("T", " ").slice(0, 16) + " UTC";
|
||||
const timeLine = `Current time: ${formattedTime} (${userTimezone}) / ${utcTime}`;
|
||||
return { userTimezone, formattedTime, timeLine };
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,9 @@ describe("resolveMemoryFlushPromptForRun", () => {
|
||||
});
|
||||
|
||||
expect(prompt).toContain("memory/2026-02-16.md");
|
||||
expect(prompt).toContain("Current time:");
|
||||
expect(prompt).toContain("(America/New_York)");
|
||||
expect(prompt).toContain(
|
||||
"Current time: Monday, February 16th, 2026 — 10:00 AM (America/New_York) / 2026-02-16 15:00 UTC",
|
||||
);
|
||||
});
|
||||
|
||||
it("does not append a duplicate current time line", () => {
|
||||
|
||||
@@ -203,7 +203,7 @@ Never modify memory/YYYY-MM-DD.md destructively.
|
||||
`;
|
||||
fs.writeFileSync(path.join(tmpDir, "AGENTS.md"), content);
|
||||
const cfg = {
|
||||
agents: { defaults: { userTimezone: "America/New_York" } },
|
||||
agents: { defaults: { userTimezone: "America/New_York", timeFormat: "12" } },
|
||||
} as OpenClawConfig;
|
||||
// 2026-03-03 14:00 UTC = 2026-03-03 09:00 EST
|
||||
const nowMs = Date.UTC(2026, 2, 3, 14, 0, 0);
|
||||
@@ -211,8 +211,9 @@ Never modify memory/YYYY-MM-DD.md destructively.
|
||||
expect(result).not.toBeNull();
|
||||
expect(result).toContain("memory/2026-03-03.md");
|
||||
expect(result).not.toContain("memory/YYYY-MM-DD.md");
|
||||
expect(result).toContain("Current time:");
|
||||
expect(result).toContain("America/New_York");
|
||||
expect(result).toContain(
|
||||
"Current time: Tuesday, March 3rd, 2026 — 9:00 AM (America/New_York) / 2026-03-03 14:00 UTC",
|
||||
);
|
||||
});
|
||||
|
||||
it("appends current time line even when no YYYY-MM-DD placeholder is present", async () => {
|
||||
|
||||
@@ -11,13 +11,14 @@ describe("buildBareSessionResetPrompt", () => {
|
||||
|
||||
it("appends current time line so agents know the date", () => {
|
||||
const cfg = {
|
||||
agents: { defaults: { userTimezone: "America/New_York" } },
|
||||
agents: { defaults: { userTimezone: "America/New_York", timeFormat: "12" } },
|
||||
} as OpenClawConfig;
|
||||
// 2026-03-03 14:00 UTC = 2026-03-03 09:00 EST
|
||||
const nowMs = Date.UTC(2026, 2, 3, 14, 0, 0);
|
||||
const prompt = buildBareSessionResetPrompt(cfg, nowMs);
|
||||
expect(prompt).toContain("Current time:");
|
||||
expect(prompt).toContain("America/New_York");
|
||||
expect(prompt).toContain(
|
||||
"Current time: Tuesday, March 3rd, 2026 — 9:00 AM (America/New_York) / 2026-03-03 14:00 UTC",
|
||||
);
|
||||
});
|
||||
|
||||
it("does not append a duplicate current time line", () => {
|
||||
|
||||
@@ -354,7 +354,7 @@ describe("runCronIsolatedAgentTurn", () => {
|
||||
const lines = call?.prompt?.split("\n") ?? [];
|
||||
expect(lines[0]).toContain("[cron:job-1");
|
||||
expect(lines[0]).toContain("do it");
|
||||
expect(lines[1]).toMatch(/^Current time: .+ \(.+\)$/);
|
||||
expect(lines[1]).toMatch(/^Current time: .+ \(.+\) \/ \d{4}-\d{2}-\d{2} \d{2}:\d{2} UTC$/);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user