Skip to content

Commit c8e40bc

Browse files
t3dotggclaude
andcommitted
fix(web): keep a one-time task's stored time when the field is unchanged
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a8336e2 commit c8e40bc

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎apps/web/src/components/settings/ScheduledTasksSettings.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ const EMPTY_DRAFT: DraftState = {
138138
intervalMinutes: "15",
139139
timeOfDay: "09:00",
140140
runAt: "",
141+
savedRunAt: "",
141142
weekdays: new Set([1, 2, 3, 4, 5]),
142143
projectId: "",
143144
threadId: "",

‎apps/web/src/components/settings/scheduledTasksSettings.logic.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,12 @@ describe("editing scheduled task branch settings", () => {
172172

173173
describe("one-time scheduled tasks", () => {
174174
it("round-trips the run time through the local date-time input", () => {
175-
const runAt = "2026-11-03T17:00:00.000Z";
175+
const runAt = "2026-11-03T17:00:42.000Z";
176176
const draft = taskToDraft({ ...legacyTask, schedule: { type: "once", runAt } });
177177
expect(draft.scheduleMode).toBe("once");
178178
expect(scheduleFromDraft(draft)).toEqual({ type: "once", runAt });
179+
const moved = scheduleFromDraft({ ...draft, runAt: "2026-11-04T09:30" });
180+
expect(moved).toEqual({ type: "once", runAt: new Date("2026-11-04T09:30").toISOString() });
179181
expect(scheduleFromDraft({ ...draft, runAt: "" })).toBeNull();
180182
});
181183
});

‎apps/web/src/components/settings/scheduledTasksSettings.logic.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export interface DraftState {
6565
readonly timeOfDay: string;
6666
/** Local date and time as a `datetime-local` input value, such as 2026-11-02T15:00. */
6767
readonly runAt: string;
68+
/** The stored ISO run time, sent back unchanged when the field was not edited. */
69+
readonly savedRunAt: string;
6870
readonly weekdays: ReadonlySet<number>;
6971
readonly projectId: string;
7072
readonly threadId: string;
@@ -158,8 +160,13 @@ export function webhookDeliveryLabel(delivery: {
158160
export function scheduleFromDraft(draft: DraftState): ScheduledTaskUpsertSchedule | null {
159161
if (scheduleDraftErrors(draft).length > 0) return null;
160162
if (draft.scheduleMode === "once") {
163+
const unchanged =
164+
draft.savedRunAt && toDateTimeLocalValue(new Date(draft.savedRunAt)) === draft.runAt;
161165
// A `datetime-local` value has no offset, so Date reads it as local time.
162-
return { type: "once", runAt: new Date(draft.runAt).toISOString() };
166+
return {
167+
type: "once",
168+
runAt: unchanged ? draft.savedRunAt : new Date(draft.runAt).toISOString(),
169+
};
163170
}
164171
if (draft.scheduleMode === "webhook") {
165172
const maxDeliveryAgeMinutes = parseMaxDeliveryAge(draft.maxDeliveryAgeMinutes);
@@ -227,6 +234,7 @@ export function taskToDraft(task: ScheduledTask): DraftState {
227234
schedule.type === "interval" ? String(Math.max(1, schedule.everyMs / 60_000)) : "15",
228235
timeOfDay: schedule.type === "fixed_time" ? schedule.timeOfDay : "09:00",
229236
runAt: schedule.type === "once" ? toDateTimeLocalValue(new Date(schedule.runAt)) : "",
237+
savedRunAt: schedule.type === "once" ? schedule.runAt : "",
230238
weekdays,
231239
projectId: task.projectId,
232240
threadId: task.threadId ?? "",

0 commit comments

Comments
 (0)