fix: align hourly automation start times (#4059)

Avoid returning off-minute hourly dtstart values as the next automation occurrence.
This commit is contained in:
Neil
2026-05-31 03:01:51 -07:00
committed by GitHub
parent 4d7d306f1c
commit 64df879f2b
2 changed files with 12 additions and 2 deletions
+10
View File
@@ -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(
+2 -2
View File
@@ -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) {