Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix(automation): reject nonexistent one-shot local times (#4551)
fengyue-xve904ea9628c12
diff --git a/frontend/src/utils/automationSchedule.test.ts b/frontend/src/utils/automationSchedule.test.tsindex 57559e302..088a539c0 100644--- a/frontend/src/utils/automationSchedule.test.ts+++ b/frontend/src/utils/automationSchedule.test.ts@@ -82,3 +82,37 @@ test('only disabled one-shot schedules with no future occurrence have ended', ()assert.equal(hasEndedOnceSchedule(once('2026-10-20T15:59:59+08:00', true), now), false)assert.equal(hasEndedOnceSchedule({ enabled: false, trigger: { type: 'cron', expr: '0 9 * * *' } }, now), false)})+++test('once triggers reject wall-clock times skipped by a timezone transition', () => {+ for (const [local, zone] of [+ ['2026-03-08 02:30', 'America/New_York'],+ ['2026-10-04 02:15', 'Australia/Lord_Howe'],+ ['2011-12-30 12:00', 'Pacific/Apia'],+ ]) {+ assert.equal(wallClockToISO(local, zone), '', `${local} in ${zone}`)+ assert.equal(triggerFromScheduleForm({ ...defaultScheduleForm(), kind: 'once', at: local }, zone), null)+ }+})++test('once triggers reject invalid calendar dates, clock fields and timezone names', () => {+ for (const local of ['2026-02-29 09:00', '2026-04-31 09:00', '2026-13-01 09:00',+ '2026-01-00 09:00', '2026-01-01 24:00', '2026-01-01 09:60', '2026-01-01 09:00oops']) {+ assert.equal(wallClockToISO(local, 'UTC'), '', local)+ }+ assert.equal(wallClockToISO('2026-01-01 09:00', 'Invalid/Timezone'), '')+})++test('valid leap days and times adjacent to transitions retain the requested wall clock', () => {+ for (const [local, zone] of [+ ['2028-02-29 09:00', 'UTC'],+ ['2026-03-08 01:30', 'America/New_York'],+ ['2026-03-08 03:30', 'America/New_York'],+ ['2026-11-01 01:30', 'America/New_York'],+ ['2026-10-04 02:30', 'Australia/Lord_Howe'],+ ]) {+ const iso = wallClockToISO(local, zone)+ assert.ok(iso, `${local} in ${zone}`)+ assert.equal(zonedWallClock(iso, zone), local)+ }+})diff --git a/frontend/src/utils/automationSchedule.ts b/frontend/src/utils/automationSchedule.tsindex dd3b11ae0..d78eef165 100644--- a/frontend/src/utils/automationSchedule.ts+++ b/frontend/src/utils/automationSchedule.ts@@ -147,7 +147,7 @@ function offsetMs(date: Date, timeZone: string): number {return Date.UTC(p.y, p.mo - 1, p.d, p.h, p.mi, p.s) - Math.floor(date.getTime() / 1000) * 1000}-const WALL = /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2})/+const WALL = /^(\d{4})-(\d{2})-(\d{2})[ T](\d{2}):(\d{2})$//** RFC 3339 instant of wall-clock time local in timeZone, or '' if local is malformed. */export function wallClockToISO(local: string, timeZone: string): string {@@ -155,10 +155,19 @@ export function wallClockToISO(local: string, timeZone: string): string {if (!match) return ''const [, y, mo, d, h, mi] = match.map(Number)const guess = Date.UTC(y, mo - 1, d, h, mi)- let t = guess - offsetMs(new Date(guess), timeZone)- // A second pass settles instants near a daylight-saving change.- t = guess - offsetMs(new Date(t), timeZone)- return new Date(t).toISOString()+ try {+ let t = guess - offsetMs(new Date(guess), timeZone)+ // A second pass settles instants near a daylight-saving change.+ t = guess - offsetMs(new Date(t), timeZone)+ const date = new Date(t)+ const p = zoneParts(date, timeZone)+ // Date.UTC normalizes invalid fields, and offset iteration can land on a+ // different local time inside a DST gap. Never schedule that other time.+ if (p.y !== y || p.mo !== mo || p.d !== d || p.h !== h || p.mi !== mi || p.s !== 0) return ''+ return date.toISOString()+ } catch {+ return ''+ }}/** Wall-clock "YYYY-MM-DD HH:mm" of iso in timeZone. */