From 029f4bd118eb3f1eca69ed3a7128997f077e0512 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 4 Sep 2025 22:59:52 +0200 Subject: ... --- .../gkleen@sif/shell/quickshell-plugins/Chrono.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'accounts/gkleen@sif/shell/quickshell-plugins/Chrono.cpp') diff --git a/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.cpp b/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.cpp index df0c5781..bc765f21 100644 --- a/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.cpp +++ b/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.cpp @@ -42,9 +42,11 @@ void Chrono::update() { } void Chrono::setTime(const std::chrono::time_point& targetTime) { + using namespace std::chrono_literals; + auto currentTime = std::chrono::system_clock::now(); auto offset = std::chrono::duration_cast(targetTime - currentTime); - this->currentTime = abs(offset.count()) < 500 ? targetTime : currentTime; + this->currentTime = abs(offset) < 500ms ? targetTime : currentTime; switch (this->mPrecision) { case Chrono::Hours: this->currentTime = std::chrono::time_point_cast(this->currentTime); @@ -58,21 +60,16 @@ void Chrono::setTime(const std::chrono::time_point& t void Chrono::schedule(const std::chrono::time_point& targetTime) { auto currentTime = std::chrono::system_clock::now(); auto offset = std::chrono::duration_cast(targetTime - currentTime); - auto nextTime = abs(offset.count()) < 500 ? targetTime : currentTime; - - { - using namespace std::chrono_literals; + auto nextTime = abs(offset) < 500ms ? targetTime : currentTime; - switch (this->mPrecision) { - case Chrono::Hours: nextTime = std::chrono::time_point_cast(nextTime) + 1h; - case Chrono::Minutes: nextTime = std::chrono::time_point_cast(nextTime) + 1min; - case Chrono::Seconds: nextTime = std::chrono::time_point_cast(nextTime) + 1s; - } + switch (this->mPrecision) { + case Chrono::Hours: nextTime = std::chrono::time_point_cast(nextTime) + 1h; + case Chrono::Minutes: nextTime = std::chrono::time_point_cast(nextTime) + 1min; + case Chrono::Seconds: nextTime = std::chrono::time_point_cast(nextTime) + 1s; } this->targetTime = nextTime; - auto delay = std::chrono::duration_cast(nextTime - currentTime); - this->timer.start(delay); + this->timer.start(std::chrono::duration_cast(nextTime - currentTime)); } QString Chrono::format(const QString& fmt) const { -- cgit v1.2.3