fix repeat scheduling

This commit is contained in:
WarmUpTill 2026-05-04 21:50:23 +02:00
parent be406ff353
commit 7f520b0f87
3 changed files with 39 additions and 1 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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;