clock: handle timezone changes (again)

This commit is contained in:
Maëlys Bras de fer 2023-07-09 01:44:39 +02:00 committed by GitHub
parent 3bfeed31bc
commit 56f956ff90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,7 +24,8 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
for (const auto& zone_name : config_["timezones"]) { for (const auto& zone_name : config_["timezones"]) {
if (!zone_name.isString()) continue; if (!zone_name.isString()) continue;
if (zone_name.asString().empty()) if (zone_name.asString().empty())
time_zones_.push_back(date::current_zone()); // nullptr means that local time should be shown
time_zones_.push_back(nullptr);
else else
try { try {
time_zones_.push_back(date::locate_zone(zone_name.asString())); time_zones_.push_back(date::locate_zone(zone_name.asString()));
@ -34,7 +35,8 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
} }
} else if (config_["timezone"].isString()) { } else if (config_["timezone"].isString()) {
if (config_["timezone"].asString().empty()) if (config_["timezone"].asString().empty())
time_zones_.push_back(date::current_zone()); // nullptr means that local time should be shown
time_zones_.push_back(nullptr);
else else
try { try {
time_zones_.push_back(date::locate_zone(config_["timezone"].asString())); time_zones_.push_back(date::locate_zone(config_["timezone"].asString()));
@ -43,10 +45,10 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
} }
} }
// If all timezones are parsed and no one is good, add current time zone. nullptr in timezones // If all timezones are parsed and no one is good
// vector means that local time should be shown
if (!time_zones_.size()) { if (!time_zones_.size()) {
time_zones_.push_back(date::current_zone()); // nullptr means that local time should be shown
time_zones_.push_back(nullptr);
} }
// Check if a particular placeholder is present in the tooltip format, to know what to calculate // Check if a particular placeholder is present in the tooltip format, to know what to calculate
@ -156,8 +158,7 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
} }
const date::time_zone* waybar::modules::Clock::current_timezone() { const date::time_zone* waybar::modules::Clock::current_timezone() {
return time_zones_[current_time_zone_idx_] ? time_zones_[current_time_zone_idx_] return is_timezone_fixed() ? time_zones_[current_time_zone_idx_] : date::current_zone();
: date::current_zone();
} }
bool waybar::modules::Clock::is_timezone_fixed() { bool waybar::modules::Clock::is_timezone_fixed() {