Fix clock is always a second off (#333)

Fix clock is always a second off
This commit is contained in:
Alex 2019-05-20 14:45:34 +02:00 committed by GitHub
commit 232073ca17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 6 deletions

View File

@ -14,16 +14,13 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
auto sub_m = auto sub_m =
std::chrono::duration_cast<std::chrono::seconds>(time_s.time_since_epoch()).count() % std::chrono::duration_cast<std::chrono::seconds>(time_s.time_since_epoch()).count() %
interval_.count(); interval_.count();
if (sub_m > 0) { thread_.sleep_until(timeout - std::chrono::seconds(sub_m));
thread_.sleep_until(timeout - std::chrono::seconds(sub_m - 1));
} else {
thread_.sleep_until(timeout - std::chrono::seconds(sub_m));
}
}; };
} }
auto waybar::modules::Clock::update() -> void { 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); auto text = fmt::format(format_, localtime);
label_.set_markup(text); label_.set_markup(text);