Centralize date/time formatting utilities (#11831)

This commit is contained in:
max
2026-02-08 04:53:31 -08:00
committed by GitHub
parent 74fbbda283
commit a1123dd9be
77 changed files with 1508 additions and 1075 deletions

View File

@@ -1,5 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { formatZonedTimestamp } from "../../auto-reply/envelope.js";
import { formatZonedTimestamp } from "../../infra/format-time/format-datetime.js";
import { injectTimestamp, timestampOptsFromConfig } from "./agent-timestamp.js";
describe("injectTimestamp", () => {
@@ -23,7 +23,7 @@ describe("injectTimestamp", () => {
it("uses channel envelope format with DOW prefix", () => {
const now = new Date();
const expected = formatZonedTimestamp(now, "America/New_York");
const expected = formatZonedTimestamp(now, { timeZone: "America/New_York" });
const result = injectTimestamp("hello", { timezone: "America/New_York" });

View File

@@ -1,6 +1,6 @@
import type { OpenClawConfig } from "../../config/types.js";
import { resolveUserTimezone } from "../../agents/date-time.js";
import { formatZonedTimestamp } from "../../auto-reply/envelope.js";
import { formatZonedTimestamp } from "../../infra/format-time/format-datetime.ts";
/**
* Cron jobs inject "Current time: ..." into their messages.
@@ -56,7 +56,7 @@ export function injectTimestamp(message: string, opts?: TimestampInjectionOption
const now = opts?.now ?? new Date();
const timezone = opts?.timezone ?? "UTC";
const formatted = formatZonedTimestamp(now, timezone);
const formatted = formatZonedTimestamp(now, { timeZone: timezone });
if (!formatted) {
return message;
}