fix: clock rounding

This commit is contained in:
Alex 2019-03-07 12:34:12 +01:00
parent ab0dcbfb2e
commit ef88f0a223

View File

@ -8,13 +8,14 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
label_.get_style_context()->add_class(id);
}
thread_ = [this] {
auto now = std::chrono::system_clock::now();
dp.emit();
auto now = std::chrono::system_clock::now();
auto timeout = std::chrono::floor<std::chrono::seconds>(now + interval_);
auto time_s = std::chrono::time_point_cast<std::chrono::seconds>(timeout);
auto sub_m =
std::chrono::duration_cast<std::chrono::seconds>(time_s.time_since_epoch()).count() % interval_.count();
thread_.sleep_until(timeout - std::chrono::seconds(sub_m - 1));
if (sub_m > 0) thread_.sleep_until(timeout - std::chrono::seconds(sub_m - 1));
else thread_.sleep_until(timeout - std::chrono::seconds(sub_m));
};
}