diff --git a/src/shared/automation-schedules.test.ts b/src/shared/automation-schedules.test.ts index f6f269a00..104af2eab 100644 --- a/src/shared/automation-schedules.test.ts +++ b/src/shared/automation-schedules.test.ts @@ -32,6 +32,16 @@ describe('automation schedules', () => { expect(latest).toBe(new Date('2026-05-13T14:00:00').getTime()) }) + it('does not return a future hourly dtstart that is off the scheduled minute', () => { + const rrule = buildAutomationRrule({ preset: 'hourly', hour: 9, minute: 0 }) + const next = nextAutomationOccurrenceAfter( + rrule, + new Date('2026-05-13T10:30:00').getTime(), + new Date('2026-05-13T09:00:00').getTime() + ) + expect(next).toBe(new Date('2026-05-13T11:00:00').getTime()) + }) + it('computes weekday schedules without returning weekend candidates', () => { const rrule = buildAutomationRrule({ preset: 'weekdays', hour: 9, minute: 30 }) const next = nextAutomationOccurrenceAfter( diff --git a/src/shared/automation-schedules.ts b/src/shared/automation-schedules.ts index 5a477163d..b83e414d3 100644 --- a/src/shared/automation-schedules.ts +++ b/src/shared/automation-schedules.ts @@ -541,10 +541,10 @@ export function nextAutomationOccurrenceAfter( const base = new Date(start) base.setMinutes(rule.byMinute, 0, 0) let candidate = base.getTime() - if (candidate <= after) { + if (candidate <= after || candidate < dtstart) { candidate += HOUR_MS } - return Math.max(candidate, dtstart) + return candidate } const candidate = scanDayCandidates(rule, Math.max(dtstart - 1, after), 1) if (candidate === null) {