From 5e43b4f587d373f52edf8c3d65e0cac2ff513fc0 Mon Sep 17 00:00:00 2001 From: RX14 Date: Sun, 19 May 2019 13:30:19 +0100 Subject: [PATCH 1/2] Fix clock is always a second off --- src/modules/clock.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index de0c27ed..18f026c7 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -23,7 +23,8 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) } auto waybar::modules::Clock::update() -> void { - auto localtime = fmt::localtime(std::time(nullptr)); + auto now = std::chrono::system_clock::now(); + auto localtime = fmt::localtime(std::chrono::system_clock::to_time_t(now)); auto text = fmt::format(format_, localtime); label_.set_markup(text); From 5314b74dae2c5f1d51c90722b431a6f9d0198e9d Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 20 May 2019 14:39:49 +0200 Subject: [PATCH 2/2] fix: remove workaround --- src/modules/clock.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 18f026c7..d2b18ca4 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -14,11 +14,7 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) auto sub_m = std::chrono::duration_cast(time_s.time_since_epoch()).count() % interval_.count(); - if (sub_m > 0) { - thread_.sleep_until(timeout - std::chrono::seconds(sub_m - 1)); - } else { - thread_.sleep_until(timeout - std::chrono::seconds(sub_m)); - } + thread_.sleep_until(timeout - std::chrono::seconds(sub_m)); }; }