Skip to content

Commit f5642f3

Browse files
committed
fix(qqbot): use Gateway timezone for reminders
1 parent a67ad03 commit f5642f3

2 files changed

Lines changed: 57 additions & 6 deletions

File tree

‎extensions/qqbot/src/engine/tools/remind-logic.test.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,54 @@ describe("engine/tools/remind-logic", () => {
5959
});
6060
});
6161

62+
it.each([
63+
{
64+
name: "uses the Gateway timezone when omitted",
65+
timezone: undefined,
66+
expectedSchedule: { kind: "cron", expr: "0 9 * * *" },
67+
expectedSummary: '⏰ Recurring reminder: "test reminder" (0 9 * * *, tz=gateway local)',
68+
},
69+
{
70+
name: "preserves an explicit IANA timezone",
71+
timezone: " America/New_York ",
72+
expectedSchedule: {
73+
kind: "cron",
74+
expr: "0 9 * * *",
75+
tz: "America/New_York",
76+
},
77+
expectedSummary: '⏰ Recurring reminder: "test reminder" (0 9 * * *, tz=America/New_York)',
78+
},
79+
])("$name for recurring reminders", async ({ timezone, expectedSchedule, expectedSummary }) => {
80+
const calls: RemindCronAction[] = [];
81+
const result = await executeScheduledRemind(
82+
{
83+
action: "add",
84+
content: "test reminder",
85+
to: "qqbot:c2c:123",
86+
time: "0 9 * * *",
87+
...(timezone ? { timezone } : {}),
88+
},
89+
{},
90+
async (params) => {
91+
calls.push(params);
92+
return { id: "job-cron" };
93+
},
94+
);
95+
96+
const call = calls[0];
97+
expect(call?.action).toBe("add");
98+
if (call?.action !== "add") {
99+
throw new Error("expected add cron action");
100+
}
101+
expect(call.job.schedule).toEqual(expectedSchedule);
102+
expect(result.details).toEqual({
103+
ok: true,
104+
action: "add",
105+
summary: expectedSummary,
106+
cronResult: { id: "job-cron" },
107+
});
108+
});
109+
62110
it("runs cron list and remove through the scheduler", async () => {
63111
const calls: unknown[] = [];
64112
await executeScheduledRemind({ action: "list" }, {}, async (params) => {

‎extensions/qqbot/src/engine/tools/remind-logic.ts‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ export interface RemindParams {
2727
jobId?: string;
2828
}
2929

30-
const QQBOT_DEFAULT_REMINDER_TIMEZONE = "Asia/Shanghai";
31-
3230
/**
3331
* Context supplied by the bridge layer so the engine can remain free of
3432
* framework / AsyncLocalStorage dependencies. `fallbackTo` and
@@ -99,7 +97,7 @@ export const RemindSchema = {
9997
timezone: {
10098
type: "string",
10199
description:
102-
"Optional IANA timezone used for cron reminders. Include it when the user provides or confirms a timezone; if omitted, QQBot preserves its existing default timezone.",
100+
"Optional IANA timezone used for cron reminders. Include it when the user provides or confirms a timezone; if omitted, Gateway cron uses the host timezone.",
103101
},
104102
name: {
105103
type: "string",
@@ -226,12 +224,16 @@ function buildOnceJob(params: RemindParams, atMs: number, to: string, accountId:
226224
function buildCronJob(params: RemindParams, to: string, accountId: string) {
227225
const content = params.content!;
228226
const name = params.name || generateJobName(content);
229-
const tz = params.timezone || QQBOT_DEFAULT_REMINDER_TIMEZONE;
227+
const timezone = params.timezone?.trim();
230228
return {
231229
action: "add" as const,
232230
job: {
233231
name,
234-
schedule: { kind: "cron" as const, expr: params.time!.trim(), tz },
232+
schedule: {
233+
kind: "cron" as const,
234+
expr: params.time!.trim(),
235+
...(timezone ? { tz: timezone } : {}),
236+
},
235237
sessionTarget: "isolated" as const,
236238
wakeMode: "now" as const,
237239
payload: {
@@ -309,11 +311,12 @@ function prepareRemindCronAction(
309311
const resolvedAccountId = ctx.fallbackAccountId || "default";
310312

311313
if (isCronExpression(params.time)) {
314+
const timezone = params.timezone?.trim();
312315
return {
313316
ok: true,
314317
action: "add",
315318
cronAction: buildCronJob(params, resolvedTo, resolvedAccountId),
316-
summary: `⏰ Recurring reminder: "${params.content}" (${params.time}, tz=${params.timezone || QQBOT_DEFAULT_REMINDER_TIMEZONE})`,
319+
summary: `⏰ Recurring reminder: "${params.content}" (${params.time}, tz=${timezone || "gateway local"})`,
317320
};
318321
}
319322

0 commit comments

Comments
 (0)