Skip to content

Commit c0061ba

Browse files
authored
Give a scheduled task a Time zone, and schedule it in that zone (#3114) (#3208)
Written-by: Dev Fixes #3207 Owner: Dev Reviewer: Reviewer Part of #3114 Tier: T1 ## What The scheduled-task form never showed the zone a rule runs in: **Every day at 09:00** always meant this device's zone, and a stored task's own zone (the row prints `Every day at 09:00 (Asia/Shanghai)`) was invisible in the one place that edits it. The form now draws a **Time zone** row for **Once** / **Every day** / **Every week** (`data-flybot="task-timezone"`, options from `Intl.supportedValuesOf('timeZone')`, the rule's own zone first and `UTC` right after it; a runtime without that API falls back to `[UTC, Asia/Shanghai]`). **Repeat** is a duration and draws no row, and a cron rule is kept as stored. The chosen zone is what the form sends: `whenFromForm` gives daily/weekly rules that `timeZone`, and reads a **Once** task's `datetime-local` wall clock in it (`2030-01-02 07:05 @ Asia/Tokyo` → `2030-01-01T22:05:00.000Z`); a wall clock the zone skips (a DST gap) is refused with the form's existing `Pick a date and time` instead of being moved an hour. Opening **Edit** fills the row from the task's stored zone, and `wallClockInput` shows the Once time in that same zone, so save-without-touching does not move the task. ## Checkpoint <!-- flybot:checkpoint --> { "pr": 3208, "claim": "Dev", "issue": 3207, "summary": "The scheduled-task form gains a Time zone row for Once, Every day and Every week, listing this runtime's IANA zones with the rule's own zone first. The chosen zone is what the form sends: daily and weekly rules carry it as time_zone, and a Once task's wall clock is read in it. A wall clock the zone skips (a DST gap) is refused with `Pick a date and time`, not moved an hour. Repeat draws no row and a cron rule is kept as stored; no host, shared-layer or authz file changed.", "files": [ "core/src/client/schedules.js", "core/test/schedules-timezone.test.js", "core/src/client/i18n.js", "core/test/schedules-client.test.js", "docs/subsystems/core-client.md", "changelog.d/3114-scheduled-task-time-zone.added.md", "core/client.js", "patches/ds-bot/0001-core-fixes.patch", "patches/ds-bot/0008-client-bundle.patch", "patches/ds-bot/files/test/schedules-timezone.test.js" ], "checks": { "ran": "TZ=UTC TMPDIR=/data/flybot-tmp npm run verify (exit 0); new file 3/3; four related suites 88/88; node core/scripts/build-client.mjs --check; node scripts/ds-bot-patches.mjs check && canonical; changelog / mojibake / testing-layers checks", "result": "green", "at": "f0c6a78a34a353154649638361cb419e6eef65d1" }, "next": "none — ready for review. T1: a green tests-ok at the tip is the gate; Dev writes no Verdict." } <!-- /flybot:checkpoint --> ## Verification at the tip Tip: `f0c6a78a34a353154649638361cb419e6eef65d1` Ran: - `cd core && TZ=UTC TMPDIR=/data/flybot-tmp node --test test/schedules-timezone.test.js` — 3 tests / 0 pass / 3 fail before the change (red first, exact failure lines below), 3 / 3 / 0 after it. - `cd core && TZ=UTC TMPDIR=/data/flybot-tmp node --test test/schedules-client.test.js test/client-bundle.test.js test/settings-readonly-pages.test.js test/i18n.test.js` — 88 tests / 88 pass / 0 fail. - `node core/scripts/build-client.mjs --check` — exit 0 on the committed `core/client.js` (24855 lines, was 24788). - `node scripts/ds-bot-patches.mjs check` — exit 1 before `generate` (`ok 10 patches apply cleanly in order`, then `core/test/schedules-timezone.test.js: committed but not produced by the patches` and four `differs from ds-bot/ + patches`); after it, exit 0 with `ok core/ equals ds-bot/ + patches/ds-bot/`; `canonical` — generate is a no-op. - `node .github/scripts/changelog.mjs check` — 12 fragments well formed; `node .github/scripts/check-mojibake.mjs --check` — 0 occurrences of U+FFFD; `node .github/scripts/testing-layers.mjs --check` — every test file and workflow classified (914 files). - `TZ=UTC TMPDIR=/data/flybot-tmp npm run verify` — exit 0, including `core` lint (0 errors) and `arch-docs`. - `git diff --numstat main -- core/src core/test docs changelog.d` — `225 19 6`: the six handwritten files, no host / shared / authz / plugins / `.github` / `policy` path touched. Not run: - **Ordering with #3112.** It is still open (not merged, head `1969402c`, `dirty`) at this tip, so the rebase contract is not exercised here. If this cut merges first, #3112 rebases and deletes the whole duplicate `core/src/client/schedules.js` time-zone hunk (`timeZoneOptions` / `wallClockInput` / `instantFromWallClock` / `whenFromForm`, the `timeZone` state, the **Time zone** row and `formStart`'s `at`), the `i18n.js` `'Time zone'` line and the `test/schedules-client.test.js` assertion, and re-runs `generate` → `check` → `canonical` so `patches/ds-bot/0001-core-fixes.patch` and `patches/ds-bot/files/test/schedules-client.test.js` lose their copy (spec §1A). If #3112 merges first instead, this cut is void: #3207 closes `not_planned`. - **A real browser on a narrow window.** The form gains one row (about 44px); the tests drive labels, values and the payload through a VM shim, not pixels, so a phone-width single screen with **Create task** still visible was not looked at. - **A DST gap against the host.** `instantFromWallClock` is asserted to throw for `2030-03-10T02:30 @ America/New_York` and the form's existing `catch` turns that into `Pick a date and time`, but no real task was created in DSH at a skipped wall clock. - **Nothing on `main`'s own open work.** No host (`core/src/host/**`, T2), shared-layer (`core/src/shared/**`, T3), `authz.js`, `plugins/**`, `.github/**` or `policy/**` line changed. ## Red first The three cases ran against the unchanged client sources: ``` # tests 3 / # pass 0 / # fail 3 not ok 1 - #3110: the scheduled-task form draws a Time zone control for a rule that carries one, and none for a repeat interval error: 'the form draws no Time zone control: ["Send to","Pick a Bot or group chat","B","Name","What to do","When","Once","Every day","Every week","Repeat","Cancel","Create task"]' not ok 2 - #3110: an edited daily task shows its own zone, saves it, and its row names the same zone error: 'the edit form names the zone its task keeps' (expected: true / operator: '==') not ok 3 - #3110: a Once task's wall clock is read in the form's zone, not this device's error: 'the form converts a wall clock in its zone' (actual: 'undefined' / expected: 'function') ``` After the change the same command reports 3 / 3 / 0. ## Scope Six handwritten files (+225/−19): `core/src/client/schedules.js` (+84/−17), `core/test/schedules-timezone.test.js` (new, 137), `core/src/client/i18n.js` (+1), `core/test/schedules-client.test.js` (+1/−1, the form's state seed list takes `start.timeZone` between `unit` and `busy`), `docs/subsystems/core-client.md` (+1/−1) and `changelog.d/3114-scheduled-task-time-zone.added.md` (new, 1). Five generated files: `core/client.js` (+78/−11, 24788 → 24855), `patches/ds-bot/0001-core-fixes.patch` (+113/−36), `patches/ds-bot/0008-client-bundle.patch` (+1031/−956), `patches/ds-bot/files/test/schedules-client.test.js` (+1/−1) and `patches/ds-bot/files/test/schedules-timezone.test.js` (new, 137). `patches/ds-bot/topics.json` is untouched. ## Ordering with #3112 #3112 is still open (not merged) at this tip and carries the same `schedules.js` +96/−17 segment, so the rebase list in **Not run** above is the contract: whoever lands second deletes the duplicate and regenerates `0001` / `files/` rather than hand-editing a patch.
1 parent bd5e65e commit c0061ba

11 files changed

Lines changed: 1585 additions & 1023 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A scheduled task's form now names the time zone its rule runs in: "Every day at 09:00" carries the zone it was saved with instead of silently meaning this device's zone, a Once task's date and time are read in that zone, and the row and the edit form name the same one ([#3114](https://github.com/ThinkFlowLab/FlyBot/issues/3114)).

‎core/client.js‎

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,7 @@ var ZH = {
12581258
"What for": "用途",
12591259
Activity: "活跃度",
12601260
"Time range": "时间范围",
1261+
"Time zone": "时区",
12611262
"All usage": "全部用量",
12621263
"Group usage by": "用量分组",
12631264
"By Bot": "按 Bot",
@@ -3943,6 +3944,59 @@ function useSchedules(actions) {
39433944
}
39443945
var schedulesReadFailure = (failure) => typeof failure === "string" && failure !== "" ? t("The scheduled tasks could not be read: {reason}", { reason: failure }) : null;
39453946
var localZone = () => Intl.DateTimeFormat().resolvedOptions().timeZone;
3947+
function timeZoneOptions(current) {
3948+
const supported = typeof Intl.supportedValuesOf === "function" ? Intl.supportedValuesOf("timeZone") : [];
3949+
const zone = String(current ?? "").trim();
3950+
const list = supported.length > 0 ? ["UTC", ...supported] : ["UTC", "Asia/Shanghai"];
3951+
if (zone !== "") list.unshift(zone);
3952+
return [...new Set(list.filter(Boolean))];
3953+
}
3954+
function zoneParts(ms, timeZone) {
3955+
const parts = new Intl.DateTimeFormat("en-US", {
3956+
timeZone: timeZone || "UTC",
3957+
hourCycle: "h23",
3958+
year: "numeric",
3959+
month: "2-digit",
3960+
day: "2-digit",
3961+
hour: "2-digit",
3962+
minute: "2-digit",
3963+
second: "2-digit"
3964+
}).formatToParts(new Date(ms));
3965+
const value = (type) => Number(parts.find((part) => part.type === type)?.value);
3966+
return Date.UTC(value("year"), value("month") - 1, value("day"), value("hour"), value("minute"), value("second"));
3967+
}
3968+
function wallClockInput(ms, timeZone) {
3969+
const at = Number(ms);
3970+
if (!Number.isFinite(at)) return "";
3971+
const parts = new Intl.DateTimeFormat("en-US", {
3972+
timeZone: String(timeZone ?? "").trim() || localZone(),
3973+
hourCycle: "h23",
3974+
year: "numeric",
3975+
month: "2-digit",
3976+
day: "2-digit",
3977+
hour: "2-digit",
3978+
minute: "2-digit"
3979+
}).formatToParts(new Date(at));
3980+
const value = (type) => parts.find((part) => part.type === type)?.value;
3981+
return value("year") ? `${value("year")}-${value("month")}-${value("day")}T${value("hour")}:${value("minute")}` : "";
3982+
}
3983+
function instantFromWallClock(wall, timeZone) {
3984+
const match = String(wall ?? "").match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?$/);
3985+
if (!match) throw new Error("Pick a date and time");
3986+
const asUtc = Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]), Number(match[4]), Number(match[5]), Number(match[6] ?? 0));
3987+
const zone = String(timeZone ?? "").trim() || "UTC";
3988+
let instant2 = asUtc;
3989+
for (let pass = 0; pass < 3; pass += 1) {
3990+
const shown = zoneParts(instant2, zone);
3991+
if (shown === asUtc) break;
3992+
instant2 -= shown - asUtc;
3993+
}
3994+
if (zoneParts(instant2, zone) === asUtc) return new Date(instant2).toISOString();
3995+
for (const probe of [instant2 - 36e5, instant2 + 36e5, instant2 - 72e5, instant2 + 72e5]) {
3996+
if (zoneParts(probe, zone) === asUtc) return new Date(probe).toISOString();
3997+
}
3998+
throw new Error("Pick a date and time");
3999+
}
39464000
var clock2 = (time) => String(time ?? "").slice(0, 5);
39474001
var when = (ms, options) => new Intl.DateTimeFormat(dateLocale(), options).format(ms);
39484002
function dayAndTime(ms) {
@@ -4117,10 +4171,6 @@ function inAnHour() {
41174171
}
41184172
var KINDS = [["at", "Once"], ["daily", "Every day"], ["weekly", "Every week"], ["every", "Repeat"]];
41194173
var UNITS = [["seconds", 1, "second", "seconds"], ["minutes", 60, "minute", "minutes"], ["hours", 3600, "hour", "hours"], ["days", 86400, "day", "days"]];
4120-
function localInput(ms) {
4121-
const date = new Date(ms);
4122-
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
4123-
}
41244174
function formStart(task) {
41254175
const seconds = task?.kind === "every" ? Number(task.everySeconds) : 3600;
41264176
const [unit, size] = seconds % 86400 === 0 ? ["days", 86400] : seconds % 3600 === 0 ? ["hours", 3600] : seconds % 60 === 0 ? ["minutes", 60] : ["seconds", 1];
@@ -4129,14 +4179,21 @@ function formStart(task) {
41294179
title: task?.title ?? "",
41304180
prompt: task?.prompt ?? "",
41314181
kind: once ? "at" : task?.kind ?? "daily",
4132-
at: once && !Number.isNaN(Date.parse(task.scheduledAt)) ? localInput(Date.parse(task.scheduledAt)) : inAnHour(),
4182+
at: once && !Number.isNaN(Date.parse(task.scheduledAt)) ? wallClockInput(Date.parse(task.scheduledAt), task?.timeZone || localZone()) : inAnHour(),
41334183
time: task?.time ? clock2(task.time) : "09:00",
41344184
weekdays: task?.kind === "weekly" && Array.isArray(task.weekdays) ? task.weekdays : [1, 2, 3, 4, 5],
41354185
count: Math.max(1, Math.round(seconds / size)),
41364186
unit,
41374187
timeZone: task?.timeZone || localZone()
41384188
};
41394189
}
4190+
function whenFromForm({ kind, at, time, weekdays, timeZone, count, unit } = {}) {
4191+
const zone = String(timeZone ?? "").trim() || localZone();
4192+
if (kind === "cron") return { kind: "keep" };
4193+
if (kind === "at") return { kind, at: instantFromWallClock(at, zone), timeZone: zone };
4194+
if (kind === "every") return { kind, seconds: Math.round(Number(count) * UNITS.find(([id]) => id === unit)[1]) };
4195+
return { kind, time, timeZone: zone, ...kind === "weekly" ? { weekdays } : {} };
4196+
}
41404197
function TaskForm({ roster, actions, start, task, onDone, onCancel }) {
41414198
const first = formStart(task);
41424199
const [target, setTarget] = (0, import_react4.useState)(task ? task.botId ?? task.roomId : start ?? "");
@@ -4148,14 +4205,10 @@ function TaskForm({ roster, actions, start, task, onDone, onCancel }) {
41484205
const [weekdays, setWeekdays] = (0, import_react4.useState)(first.weekdays);
41494206
const [count, setCount] = (0, import_react4.useState)(first.count);
41504207
const [unit, setUnit] = (0, import_react4.useState)(first.unit);
4208+
const [timeZone, setTimeZone] = (0, import_react4.useState)(first.timeZone);
41514209
const [busy, setBusy] = (0, import_react4.useState)(false);
41524210
const [error, setError] = (0, import_react4.useState)("");
4153-
const timing = () => {
4154-
if (kind === "cron") return { kind: "keep" };
4155-
if (kind === "at") return { kind, at: new Date(at).toISOString(), timeZone: first.timeZone };
4156-
if (kind === "every") return { kind, seconds: Math.round(Number(count) * UNITS.find(([id]) => id === unit)[1]) };
4157-
return { kind, time, timeZone: first.timeZone, ...kind === "weekly" ? { weekdays } : {} };
4158-
};
4211+
const timing = () => whenFromForm({ kind, at, time, weekdays, timeZone, count, unit });
41594212
const submit = (event) => {
41604213
event.preventDefault();
41614214
if (busy || target === "") return;
@@ -4234,6 +4287,20 @@ function TaskForm({ roster, actions, start, task, onDone, onCancel }) {
42344287
) : null
42354288
)
42364289
),
4290+
// Which 09:00 this is: only the rules DSH keeps a zone for show it — a repeat interval has
4291+
// none, and a cron rule is kept as stored unless the kind changes (#3110).
4292+
kind === "at" || kind === "daily" || kind === "weekly" ? (0, import_react4.createElement)(
4293+
"label",
4294+
{ className: "bt-set-row bt-bs-row" },
4295+
(0, import_react4.createElement)("span", { className: "bt-set-copy" }, (0, import_react4.createElement)("span", { className: "bt-bs-label" }, t("Time zone"))),
4296+
(0, import_react4.createElement)("select", {
4297+
className: "bt-select bt-task-timezone",
4298+
"data-flybot": "task-timezone",
4299+
value: timeZone,
4300+
"aria-label": t("Time zone"),
4301+
onChange: (event) => setTimeZone(event.target.value)
4302+
}, timeZoneOptions(timeZone).map((zone) => (0, import_react4.createElement)("option", { key: zone, value: zone }, zone)))
4303+
) : null,
42374304
error ? (0, import_react4.createElement)("div", { className: "bt-set-row" }, (0, import_react4.createElement)("span", { className: "bt-danger bt-set-hint", role: "alert" }, error)) : null,
42384305
(0, import_react4.createElement)(
42394306
"div",

‎core/src/client/i18n.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,7 @@ const ZH = {
12121212
'What for': '用途',
12131213
Activity: '活跃度',
12141214
'Time range': '时间范围',
1215+
'Time zone': '时区',
12151216
'All usage': '全部用量',
12161217
'Group usage by': '用量分组',
12171218
'By Bot': '按 Bot',

‎core/src/client/schedules.js‎

Lines changed: 84 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,63 @@ export const schedulesReadFailure = failure => (typeof failure === 'string' && f
5252
: null)
5353

5454
const localZone = () => Intl.DateTimeFormat().resolvedOptions().timeZone
55+
56+
// The form sends an IANA zone with the rules that carry one (#3110). This runtime's own list is
57+
// the choices; a zone already on the task stays listed even when the runtime omits it.
58+
export function timeZoneOptions(current) {
59+
const supported = typeof Intl.supportedValuesOf === 'function' ? Intl.supportedValuesOf('timeZone') : []
60+
const zone = String(current ?? '').trim()
61+
const list = supported.length > 0 ? ['UTC', ...supported] : ['UTC', 'Asia/Shanghai']
62+
if (zone !== '') list.unshift(zone)
63+
return [...new Set(list.filter(Boolean))]
64+
}
65+
66+
// The wall clock a zone shows for an instant, as the parts of a datetime-local value.
67+
function zoneParts(ms, timeZone) {
68+
const parts = new Intl.DateTimeFormat('en-US', {
69+
timeZone: timeZone || 'UTC', hourCycle: 'h23', year: 'numeric', month: '2-digit', day: '2-digit',
70+
hour: '2-digit', minute: '2-digit', second: '2-digit',
71+
}).formatToParts(new Date(ms))
72+
const value = type => Number(parts.find(part => part.type === type)?.value)
73+
return Date.UTC(value('year'), value('month') - 1, value('day'), value('hour'), value('minute'), value('second'))
74+
}
75+
76+
// A stored instant as a datetime-local value in the zone the task keeps (#3110), not this device's.
77+
export function wallClockInput(ms, timeZone) {
78+
const at = Number(ms)
79+
if (!Number.isFinite(at)) return ''
80+
const parts = new Intl.DateTimeFormat('en-US', {
81+
timeZone: String(timeZone ?? '').trim() || localZone(), hourCycle: 'h23',
82+
year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit',
83+
}).formatToParts(new Date(at))
84+
const value = type => parts.find(part => part.type === type)?.value
85+
return value('year') ? `${value('year')}-${value('month')}-${value('day')}T${value('hour')}:${value('minute')}` : ''
86+
}
87+
88+
// The instant a wall clock names in a zone (#3110). DSH stores the instant; a wall clock the zone
89+
// skips (a DST gap) is refused rather than moved to another hour.
90+
export function instantFromWallClock(wall, timeZone) {
91+
const match = String(wall ?? '').match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?$/)
92+
if (!match) throw new Error('Pick a date and time')
93+
const asUtc = Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]), Number(match[4]), Number(match[5]), Number(match[6] ?? 0))
94+
const zone = String(timeZone ?? '').trim() || 'UTC'
95+
let instant = asUtc
96+
// Two passes settle the offset: the first guess is read back in the zone, and the difference
97+
// between what it shows and what we meant is the offset to remove.
98+
for (let pass = 0; pass < 3; pass += 1) {
99+
const shown = zoneParts(instant, zone)
100+
if (shown === asUtc) break
101+
instant -= shown - asUtc
102+
}
103+
if (zoneParts(instant, zone) === asUtc) return new Date(instant).toISOString()
104+
// A clock the zone gains (a DST gap) has no instant: refuse it, as the host refuses a time it
105+
// cannot run.
106+
for (const probe of [instant - 3_600_000, instant + 3_600_000, instant - 7_200_000, instant + 7_200_000]) {
107+
if (zoneParts(probe, zone) === asUtc) return new Date(probe).toISOString()
108+
}
109+
throw new Error('Pick a date and time')
110+
}
111+
55112
const clock = time => String(time ?? '').slice(0, 5)
56113
const when = (ms, options) => new Intl.DateTimeFormat(dateLocale(), options).format(ms)
57114
function dayAndTime(ms) {
@@ -221,11 +278,6 @@ const KINDS = [['at', 'Once'], ['daily', 'Every day'], ['weekly', 'Every week'],
221278
// The form says one unit with one count ("1 minute"), so each unit carries both words.
222279
const UNITS = [['seconds', 1, 'second', 'seconds'], ['minutes', 60, 'minute', 'minutes'], ['hours', 3600, 'hour', 'hours'], ['days', 86400, 'day', 'days']]
223280

224-
// A stored instant as the value of a datetime-local input, in this browser's zone.
225-
function localInput(ms) {
226-
const date = new Date(ms)
227-
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`
228-
}
229281
// What the form starts with: a new task's defaults, or the edited task's own values.
230282
// A cron rule has no control here, so it is kept unless another kind is picked.
231283
export function formStart(task) {
@@ -236,7 +288,7 @@ export function formStart(task) {
236288
title: task?.title ?? '',
237289
prompt: task?.prompt ?? '',
238290
kind: once ? 'at' : task?.kind ?? 'daily',
239-
at: once && !Number.isNaN(Date.parse(task.scheduledAt)) ? localInput(Date.parse(task.scheduledAt)) : inAnHour(),
291+
at: once && !Number.isNaN(Date.parse(task.scheduledAt)) ? wallClockInput(Date.parse(task.scheduledAt), task?.timeZone || localZone()) : inAnHour(),
240292
time: task?.time ? clock(task.time) : '09:00',
241293
weekdays: task?.kind === 'weekly' && Array.isArray(task.weekdays) ? task.weekdays : [1, 2, 3, 4, 5],
242294
count: Math.max(1, Math.round(seconds / size)),
@@ -245,6 +297,17 @@ export function formStart(task) {
245297
}
246298
}
247299

300+
// The form's timing as the host takes it (#3110): the zone the form shows is the one a daily or
301+
// weekly rule carries, and the one a Once task's wall clock is read in. A repeat interval is a
302+
// duration, so it carries no zone at all.
303+
export function whenFromForm({ kind, at, time, weekdays, timeZone, count, unit } = {}) {
304+
const zone = String(timeZone ?? '').trim() || localZone()
305+
if (kind === 'cron') return { kind: 'keep' }
306+
if (kind === 'at') return { kind, at: instantFromWallClock(at, zone), timeZone: zone }
307+
if (kind === 'every') return { kind, seconds: Math.round(Number(count) * UNITS.find(([id]) => id === unit)[1]) }
308+
return { kind, time, timeZone: zone, ...(kind === 'weekly' ? { weekdays } : {}) }
309+
}
310+
248311
function TaskForm({ roster, actions, start, task, onDone, onCancel }) {
249312
// A task goes to a Bot's chat or to a group chat, where it reads as your message.
250313
const first = formStart(task)
@@ -259,19 +322,10 @@ function TaskForm({ roster, actions, start, task, onDone, onCancel }) {
259322
const [weekdays, setWeekdays] = useState(first.weekdays)
260323
const [count, setCount] = useState(first.count)
261324
const [unit, setUnit] = useState(first.unit)
325+
const [timeZone, setTimeZone] = useState(first.timeZone)
262326
const [busy, setBusy] = useState(false)
263327
const [error, setError] = useState('')
264-
const timing = () => {
265-
if (kind === 'cron') return { kind: 'keep' }
266-
// A once task is an instant; the host reads its wall clock in this zone when quiet
267-
// hours are on (#1166). The others carry their zone with the time itself.
268-
if (kind === 'at') return { kind, at: new Date(at).toISOString(), timeZone: first.timeZone }
269-
// Seconds, not minutes: DSH takes any interval of 60s or more, so a 90s repeat must
270-
// survive the form instead of being rounded to two minutes (#1651).
271-
if (kind === 'every') return { kind, seconds: Math.round(Number(count) * UNITS.find(([id]) => id === unit)[1]) }
272-
// An edited task keeps its own time zone; a new one takes this browser's.
273-
return { kind, time, timeZone: first.timeZone, ...(kind === 'weekly' ? { weekdays } : {}) }
274-
}
328+
const timing = () => whenFromForm({ kind, at, time, weekdays, timeZone, count, unit })
275329
const submit = (event) => {
276330
event.preventDefault()
277331
if (busy || target === '') return
@@ -313,6 +367,19 @@ function TaskForm({ roster, actions, start, task, onDone, onCancel }) {
313367
h('input', { className: 'bt-input bt-task-count', type: 'number', min: 1, value: count, 'aria-label': t('How many'), onChange: event => setCount(event.target.value) }),
314368
h('select', { className: 'bt-select bt-task-unit', value: unit, 'aria-label': t('Unit'), onChange: event => setUnit(event.target.value) },
315369
UNITS.map(([id, , one, many]) => h('option', { key: id, value: id }, t(Number(count) === 1 ? one : many))))) : null)),
370+
// Which 09:00 this is: only the rules DSH keeps a zone for show it — a repeat interval has
371+
// none, and a cron rule is kept as stored unless the kind changes (#3110).
372+
kind === 'at' || kind === 'daily' || kind === 'weekly'
373+
? h('label', { className: 'bt-set-row bt-bs-row' },
374+
h('span', { className: 'bt-set-copy' }, h('span', { className: 'bt-bs-label' }, t('Time zone'))),
375+
h('select', {
376+
className: 'bt-select bt-task-timezone',
377+
'data-flybot': 'task-timezone',
378+
value: timeZone,
379+
'aria-label': t('Time zone'),
380+
onChange: event => setTimeZone(event.target.value),
381+
}, timeZoneOptions(timeZone).map(zone => h('option', { key: zone, value: zone }, zone))))
382+
: null,
316383
error ? h('div', { className: 'bt-set-row' }, h('span', { className: 'bt-danger bt-set-hint', role: 'alert' }, error)) : null,
317384
h('div', { className: 'bt-set-row bt-task-foot' },
318385
h('button', { type: 'button', className: 'bt-soft bt-soft-sm', onClick: onCancel }, t('Cancel')),

‎core/test/schedules-client.test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ test('#2232: Quiet hours and the form announce a refusal, not only print it', as
791791
const start = formStart(ACTIVE)
792792
seeded.push(
793793
{ available: true, tasks: [] }, true, null, false, '', '22:00', '07:00',
794-
'b1', start.title, start.prompt, start.kind, start.at, start.time, start.weekdays, start.count, start.unit, false, sentence,
794+
'b1', start.title, start.prompt, start.kind, start.at, start.time, start.weekdays, start.count, start.unit, start.timeZone, false, sentence,
795795
)
796796
const formShown = render(SchedulesPage({ roster: ROSTER, actions: formActions, start: 'b1' }))
797797
const formAlerts = alertsOf(formShown)

0 commit comments

Comments
 (0)