diff --git a/src/lib/components/automations/AutomationEditor.svelte b/src/lib/components/automations/AutomationEditor.svelte index 1f086ac098..e71bb4e9cf 100644 --- a/src/lib/components/automations/AutomationEditor.svelte +++ b/src/lib/components/automations/AutomationEditor.svelte @@ -95,8 +95,8 @@ }; const formatSchedule = (rrule: string): string => { + const match = rrule.match(/DTSTART[^:]*:(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})/i); if (/COUNT=1(?!\d)/.test(rrule)) { - const match = rrule.match(/DTSTART:(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})/); if (match) { const d = new Date(`${match[1]}-${match[2]}-${match[3]}T${match[4]}:${match[5]}`); return `${$i18n.t('Once')} · ${d.toLocaleDateString(undefined, { @@ -120,8 +120,8 @@ }); const freq = parts.FREQ || ''; - const hour = parseInt(parts.BYHOUR || '0'); - const minute = (parts.BYMINUTE || '0').padStart(2, '0'); + const hour = parseInt(parts.BYHOUR || match?.[4] || '0'); + const minute = (parts.BYMINUTE || match?.[5] || '0').padStart(2, '0'); const interval = parseInt(parts.INTERVAL || '1'); const ampm = hour >= 12 ? 'PM' : 'AM'; const hour12 = hour % 12 || 12; diff --git a/src/lib/components/automations/ScheduleDropdown.svelte b/src/lib/components/automations/ScheduleDropdown.svelte index fba15c5220..c1d03cee11 100644 --- a/src/lib/components/automations/ScheduleDropdown.svelte +++ b/src/lib/components/automations/ScheduleDropdown.svelte @@ -105,10 +105,10 @@ }; export const parseRrule = (s: string) => { + const match = s.match(/DTSTART[^:]*:(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})/i); // Detect ONCE (COUNT=1 with DTSTART) if (/COUNT=1(?!\d)/.test(s)) { frequency = 'ONCE'; - const match = s.match(/DTSTART:(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})/); if (match) { onceDate = `${match[1]}-${match[2]}-${match[3]}`; onceTime = `${match[4]}:${match[5]}`; @@ -134,8 +134,8 @@ } frequency = freq; interval = parseInt(parts.INTERVAL || '1'); - hour = parseInt(parts.BYHOUR || '9'); - minute = parseInt(parts.BYMINUTE || '0'); + hour = parseInt(parts.BYHOUR || match?.[4] || '9'); + minute = parseInt(parts.BYMINUTE || match?.[5] || '0'); selectedDays = parts.BYDAY ? parts.BYDAY.split(',') : []; monthDay = parseInt(parts.BYMONTHDAY || '1'); }; diff --git a/src/routes/(app)/automations/+page.svelte b/src/routes/(app)/automations/+page.svelte index 6dd7267eac..9dd9ffbdb3 100644 --- a/src/routes/(app)/automations/+page.svelte +++ b/src/routes/(app)/automations/+page.svelte @@ -308,9 +308,9 @@ }; const formatRRule = (rrule: string): string => { + const match = rrule.match(/DTSTART[^:]*:(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})/i); // Detect one-time schedule (ONCE) if (/COUNT=1(?!\d)/.test(rrule)) { - const match = rrule.match(/DTSTART:(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})/); if (match) { const d = new Date(`${match[1]}-${match[2]}-${match[3]}T${match[4]}:${match[5]}`); return `Once · ${d.toLocaleDateString(undefined, { month: 'short', day: 'numeric' })} ${d.toLocaleTimeString(undefined, { hour: 'numeric', minute: '2-digit' })}`; @@ -329,8 +329,8 @@ if (k && v) parts[k] = v; }); const freq = parts.FREQ || ''; - const hour = parseInt(parts.BYHOUR || '0'); - const min = (parts.BYMINUTE || '0').padStart(2, '0'); + const hour = parseInt(parts.BYHOUR || match?.[4] || '0'); + const min = (parts.BYMINUTE || match?.[5] || '0').padStart(2, '0'); const iv = parseInt(parts.INTERVAL || '1'); const ampm = hour >= 12 ? 'PM' : 'AM'; const h12 = hour % 12 || 12;