diff options
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell-plugins/Chrono.cpp')
-rw-r--r-- | accounts/gkleen@sif/shell/quickshell-plugins/Chrono.cpp | 21 |
1 files changed, 9 insertions, 12 deletions
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() { | |||
42 | } | 42 | } |
43 | 43 | ||
44 | void Chrono::setTime(const std::chrono::time_point<std::chrono::system_clock>& targetTime) { | 44 | void Chrono::setTime(const std::chrono::time_point<std::chrono::system_clock>& targetTime) { |
45 | using namespace std::chrono_literals; | ||
46 | |||
45 | auto currentTime = std::chrono::system_clock::now(); | 47 | auto currentTime = std::chrono::system_clock::now(); |
46 | auto offset = std::chrono::duration_cast<std::chrono::milliseconds>(targetTime - currentTime); | 48 | auto offset = std::chrono::duration_cast<std::chrono::milliseconds>(targetTime - currentTime); |
47 | this->currentTime = abs(offset.count()) < 500 ? targetTime : currentTime; | 49 | this->currentTime = abs(offset) < 500ms ? targetTime : currentTime; |
48 | 50 | ||
49 | switch (this->mPrecision) { | 51 | switch (this->mPrecision) { |
50 | case Chrono::Hours: this->currentTime = std::chrono::time_point_cast<std::chrono::hours>(this->currentTime); | 52 | case Chrono::Hours: this->currentTime = std::chrono::time_point_cast<std::chrono::hours>(this->currentTime); |
@@ -58,21 +60,16 @@ void Chrono::setTime(const std::chrono::time_point<std::chrono::system_clock>& t | |||
58 | void Chrono::schedule(const std::chrono::time_point<std::chrono::system_clock>& targetTime) { | 60 | void Chrono::schedule(const std::chrono::time_point<std::chrono::system_clock>& targetTime) { |
59 | auto currentTime = std::chrono::system_clock::now(); | 61 | auto currentTime = std::chrono::system_clock::now(); |
60 | auto offset = std::chrono::duration_cast<std::chrono::milliseconds>(targetTime - currentTime); | 62 | auto offset = std::chrono::duration_cast<std::chrono::milliseconds>(targetTime - currentTime); |
61 | auto nextTime = abs(offset.count()) < 500 ? targetTime : currentTime; | 63 | auto nextTime = abs(offset) < 500ms ? targetTime : currentTime; |
62 | |||
63 | { | ||
64 | using namespace std::chrono_literals; | ||
65 | 64 | ||
66 | switch (this->mPrecision) { | 65 | switch (this->mPrecision) { |
67 | case Chrono::Hours: nextTime = std::chrono::time_point_cast<std::chrono::hours>(nextTime) + 1h; | 66 | case Chrono::Hours: nextTime = std::chrono::time_point_cast<std::chrono::hours>(nextTime) + 1h; |
68 | case Chrono::Minutes: nextTime = std::chrono::time_point_cast<std::chrono::minutes>(nextTime) + 1min; | 67 | case Chrono::Minutes: nextTime = std::chrono::time_point_cast<std::chrono::minutes>(nextTime) + 1min; |
69 | case Chrono::Seconds: nextTime = std::chrono::time_point_cast<std::chrono::seconds>(nextTime) + 1s; | 68 | case Chrono::Seconds: nextTime = std::chrono::time_point_cast<std::chrono::seconds>(nextTime) + 1s; |
70 | } | ||
71 | } | 69 | } |
72 | 70 | ||
73 | this->targetTime = nextTime; | 71 | this->targetTime = nextTime; |
74 | auto delay = std::chrono::duration_cast<std::chrono::milliseconds>(nextTime - currentTime); | 72 | this->timer.start(std::chrono::duration_cast<std::chrono::milliseconds>(nextTime - currentTime)); |
75 | this->timer.start(delay); | ||
76 | } | 73 | } |
77 | 74 | ||
78 | QString Chrono::format(const QString& fmt) const { | 75 | QString Chrono::format(const QString& fmt) const { |