plugins/nightlight: Guard against invalid timings in the config

Morning and evening timings should be ordered correctly. When computing
the daylight duration, that ternary operator should not be needed and it
hides other bugs.
This commit is contained in:
Vlad Zahorodnii 2024-06-14 18:00:53 +03:00
parent 07f266e7c7
commit 786b3ffbae

View file

@ -279,8 +279,12 @@ void NightLightManager::readConfig()
// fixed timings
QTime mrB = QTime::fromString(s->morningBeginFixed(), "hhmm");
QTime evB = QTime::fromString(s->eveningBeginFixed(), "hhmm");
if (mrB >= evB) {
mrB = QTime(6, 0);
evB = QTime(18, 0);
}
int diffME = evB > mrB ? mrB.msecsTo(evB) : evB.msecsTo(mrB);
int diffME = mrB.msecsTo(evB);
int diffMin = std::min(diffME, MSC_DAY - diffME);
int trTime = s->transitionTime() * 1000 * 60;