Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3125 #3128

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/modules/clock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
auto get_calendar(const year_month_day& today, const year_month_day& ymd, const time_zone* tz)
-> const std::string;

// get local time zone
auto local_zone() -> const time_zone*;

Check warning on line 56 in include/modules/clock.hpp

View workflow job for this annotation

GitHub Actions / build

include/modules/clock.hpp:56:8 [readability-identifier-naming]

invalid case style for function 'local_zone'

// time zoned time in tooltip
const bool tzInTooltip_; // if need to print time zones text
std::vector<const time_zone*> tzList_; // time zones list
Expand Down
18 changes: 15 additions & 3 deletions src/modules/clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
fmtMap_.insert({3, config_[kCldPlaceholder]["format"]["today"].asString()});
cldBaseDay_ =
year_month_day{
floor<days>(zoned_time{current_zone(), system_clock::now()}.get_local_time())}
floor<days>(zoned_time{local_zone(), system_clock::now()}.get_local_time())}
.day();
} else
fmtMap_.insert({3, "{}"});
Expand Down Expand Up @@ -131,7 +131,7 @@
}

auto waybar::modules::Clock::update() -> void {
const auto* tz = tzList_[tzCurrIdx_] != nullptr ? tzList_[tzCurrIdx_] : current_zone();
const auto* tz = tzList_[tzCurrIdx_] != nullptr ? tzList_[tzCurrIdx_] : local_zone();
const zoned_time now{tz, floor<seconds>(system_clock::now())};

label_.set_markup(fmt_lib::vformat(locale_, format_, fmt_lib::make_format_args(now)));
Expand Down Expand Up @@ -168,7 +168,7 @@
std::stringstream os;
for (size_t tz_idx{0}; tz_idx < tzList_.size(); ++tz_idx) {
if (static_cast<int>(tz_idx) == tzCurrIdx_) continue;
const auto* tz = tzList_[tz_idx] != nullptr ? tzList_[tz_idx] : current_zone();
const auto* tz = tzList_[tz_idx] != nullptr ? tzList_[tz_idx] : local_zone();
auto zt{zoned_time{tz, now}};
os << fmt_lib::vformat(locale_, format_, fmt_lib::make_format_args(zt)) << '\n';
}
Expand Down Expand Up @@ -393,6 +393,18 @@
return os.str();
}

auto waybar::modules::Clock::local_zone() -> const time_zone* {

Check warning on line 396 in src/modules/clock.cpp

View workflow job for this annotation

GitHub Actions / build

src/modules/clock.cpp:396:30 [readability-convert-member-functions-to-static]

method 'local_zone' can be made static
const char* tz_name = getenv("TZ");

Check warning on line 397 in src/modules/clock.cpp

View workflow job for this annotation

GitHub Actions / build

src/modules/clock.cpp:397:15 [readability-identifier-naming]

invalid case style for variable 'tz_name'
if (tz_name) {

Check warning on line 398 in src/modules/clock.cpp

View workflow job for this annotation

GitHub Actions / build

src/modules/clock.cpp:398:7 [readability-implicit-bool-conversion]

implicit conversion 'const char *' -> bool
try {
return locate_zone(tz_name);
} catch (const std::runtime_error& e) {
spdlog::warn("Timezone: {0}. {1}", tz_name, e.what());
}
}
return current_zone();
}

// Actions handler
auto waybar::modules::Clock::doAction(const std::string& name) -> void {
if (actionMap_[name]) {
Expand Down
Loading