fix: align hourly automation start times (#4059)
Avoid returning off-minute hourly dtstart values as the next automation occurrence.
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user