From 786b3ffbaedc5d4246d8a9d0e26b287d7cc00c48 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Fri, 14 Jun 2024 18:00:53 +0300 Subject: [PATCH] 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. --- src/plugins/nightlight/nightlightmanager.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plugins/nightlight/nightlightmanager.cpp b/src/plugins/nightlight/nightlightmanager.cpp index f92b615a95..b94dc99316 100644 --- a/src/plugins/nightlight/nightlightmanager.cpp +++ b/src/plugins/nightlight/nightlightmanager.cpp @@ -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;