From d343f616fc0964606e533a2a382c88ef140483d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlys=20Bras=20de=20fer?= Date: Tue, 16 Jan 2024 21:35:42 +0100 Subject: [PATCH 1/2] clock: handle timezone changes (again again) --- src/modules/clock.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index d78d4c26..5bfd0c49 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -28,7 +28,7 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) if (!zone_name.isString()) continue; if (zone_name.asString().empty()) // local time should be shown - tzList_.push_back(current_zone()); + tzList_.push_back(nullptr); else try { tzList_.push_back(locate_zone(zone_name.asString())); @@ -39,7 +39,7 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) } else if (config_["timezone"].isString()) { if (config_["timezone"].asString().empty()) // local time should be shown - tzList_.push_back(current_zone()); + tzList_.push_back(nullptr); else try { tzList_.push_back(locate_zone(config_["timezone"].asString())); @@ -47,7 +47,7 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) spdlog::warn("Timezone: {0}. {1}", config_["timezone"].asString(), e.what()); } } - if (!tzList_.size()) tzList_.push_back(current_zone()); + if (!tzList_.size()) tzList_.push_back(nullptr); // Calendar properties if (cldInTooltip_) { @@ -84,7 +84,7 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) fmtMap_.insert({3, config_[kCldPlaceholder]["format"]["today"].asString()}); cldBaseDay_ = year_month_day{ - floor(zoned_time{current_zone(), system_clock::now()}.get_local_time())} + floor(zoned_time{nullptr, system_clock::now()}.get_local_time())} .day(); } else fmtMap_.insert({3, "{}"}); @@ -127,7 +127,7 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) } auto waybar::modules::Clock::update() -> void { - auto tz{tzList_[tzCurrIdx_]}; + auto tz{tzList_[tzCurrIdx_] ?: current_zone()}; const zoned_time now{tz, floor(system_clock::now())}; label_.set_markup(fmt_lib::vformat(locale_, format_, fmt_lib::make_format_args(now))); From 4f0fbaba8e918394ee8cf0e9fa390b478380ad14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlys=20Bras=20de=20fer?= Date: Wed, 17 Jan 2024 13:30:32 +0100 Subject: [PATCH 2/2] clock: fix construction with calendar.format.today --- src/modules/clock.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 5bfd0c49..495dfab3 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -84,7 +84,7 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) fmtMap_.insert({3, config_[kCldPlaceholder]["format"]["today"].asString()}); cldBaseDay_ = year_month_day{ - floor(zoned_time{nullptr, system_clock::now()}.get_local_time())} + floor(zoned_time{current_zone(), system_clock::now()}.get_local_time())} .day(); } else fmtMap_.insert({3, "{}"});