[AI-assisted] fix(dreaming): use host local timezone for diary timestamps (#65034)

* fix(dreaming): use host local timezone when timezone is not configured

When `memory.dreaming.timezone` is unset, `formatNarrativeDate()`
previously defaulted to UTC, causing diary timestamps in DREAMS.md and
the Control UI to display UTC time as though it were the user's local
time. For example, a PDT user seeing 9:46 PM instead of the correct
2:46 PM.

Drop the UTC fallback so `Intl.DateTimeFormat` automatically uses the
host's timezone when no explicit timezone is provided. Users who have
set `agents.defaults.userTimezone` or `dreaming.timezone` are
unaffected.

Fixes #65027

* docs(changelog): add dreaming timezone entry

* Update CHANGELOG.md

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
neo1027144
2026-04-12 23:38:18 +08:00
committed by GitHub
parent b8c95e5825
commit 7d9e349129
3 changed files with 32 additions and 1 deletions

View File

@@ -122,6 +122,36 @@ describe("formatNarrativeDate", () => {
expect(date).toContain("2026");
expect(date).toContain("3:00");
});
it("applies an explicit timezone", () => {
// 2026-04-11T21:46:55Z in America/Los_Angeles (PDT, UTC-7) → 2:46 PM
const date = formatNarrativeDate(
Date.parse("2026-04-11T21:46:55Z"),
"America/Los_Angeles",
);
expect(date).toContain("2:46");
expect(date).toContain("PM");
});
it("uses host local timezone when timezone is undefined (#65027)", () => {
// Force a non-UTC host timezone so this test is meaningful on UTC CI
// runners where the old `?? "UTC"` fallback would silently pass.
const originalTZ = process.env.TZ;
try {
process.env.TZ = "America/Los_Angeles"; // PDT = UTC-7
const epochMs = Date.parse("2026-04-11T21:46:55Z");
const result = formatNarrativeDate(epochMs);
// 21:46 UTC → 14:46 PDT → "2:46 PM"
expect(result).toContain("2:46");
expect(result).toContain("PM");
} finally {
if (originalTZ === undefined) {
delete process.env.TZ;
} else {
process.env.TZ = originalTZ;
}
}
});
});
describe("buildDiaryEntry", () => {

View File

@@ -231,7 +231,7 @@ export function extractNarrativeText(messages: unknown[]): string | null {
export function formatNarrativeDate(epochMs: number, timezone?: string): string {
const opts: Intl.DateTimeFormatOptions = {
timeZone: timezone ?? "UTC",
timeZone: timezone,
year: "numeric",
month: "long",
day: "numeric",