mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
fix: clock rounding
This commit is contained in:
parent
ab0dcbfb2e
commit
ef88f0a223
@ -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));
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user