From 7f520b0f874cd0277e5d965a7bc1504c65cbfdc0 Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Mon, 4 May 2026 21:50:23 +0200 Subject: [PATCH] fix repeat scheduling --- .../schedule/macro-schedule-entry-dialog.cpp | 7 +++- plugins/schedule/macro-schedule.cpp | 32 +++++++++++++++++++ plugins/schedule/macro-schedule.hpp | 1 + 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/plugins/schedule/macro-schedule-entry-dialog.cpp b/plugins/schedule/macro-schedule-entry-dialog.cpp index 41cc8612..ec4de87d 100644 --- a/plugins/schedule/macro-schedule-entry-dialog.cpp +++ b/plugins/schedule/macro-schedule-entry-dialog.cpp @@ -348,7 +348,12 @@ void MacroScheduleEntryDialog::ApplyToEntry(MacroScheduleEntry &entry) const const QString macroName = _macroSel->currentText(); entry.macro = macroName; - entry.startDateTime = _startDateTime->dateTime(); + const QDateTime newStartDateTime = _startDateTime->dateTime(); + const bool startChanged = (newStartDateTime != entry.startDateTime); + entry.startDateTime = newStartDateTime; + if (startChanged) { + entry.FastForwardTo(QDateTime::currentDateTime()); + } entry.hasEndDate = _hasEndDate->isChecked(); if (entry.hasEndDate) { diff --git a/plugins/schedule/macro-schedule.cpp b/plugins/schedule/macro-schedule.cpp index fa4c6530..9ada0979 100644 --- a/plugins/schedule/macro-schedule.cpp +++ b/plugins/schedule/macro-schedule.cpp @@ -293,6 +293,38 @@ void MacroScheduleEntry::MarkTriggered(const QDateTime &now) lastTriggered = now; } +void MacroScheduleEntry::FastForwardTo(const QDateTime &now) +{ + timesTriggered = 0; + lastTriggered = QDateTime(); + + if (!startDateTime.isValid()) { + return; + } + + if (repeatType == RepeatType::NONE) { + // One-shot: count it as triggered if the start lies in the past. + if (startDateTime <= now) { + timesTriggered = 1; + lastTriggered = startDateTime; + } + return; + } + + // Repeating: walk intervals from startDateTime and count each one + // that falls at or before 'now'. + QDateTime t = startDateTime; + while (t <= now) { + ++timesTriggered; + lastTriggered = t; + const QDateTime next = advanceFrom(t); + if (!next.isValid()) { + break; + } + t = next; + } +} + QString MacroScheduleEntry::GetRepeatDescription() const { if (repeatType == RepeatType::NONE) { diff --git a/plugins/schedule/macro-schedule.hpp b/plugins/schedule/macro-schedule.hpp index d2aa2241..22a97b3e 100644 --- a/plugins/schedule/macro-schedule.hpp +++ b/plugins/schedule/macro-schedule.hpp @@ -41,6 +41,7 @@ public: bool ShouldTrigger(const QDateTime &now) const; void MarkTriggered(const QDateTime &now); bool IsExpired() const; + void FastForwardTo(const QDateTime &now); QString GetSummary() const; QString GetRepeatDescription() const;