fix: lint clock

This commit is contained in:
Alex 2022-04-15 14:39:13 +02:00
parent 73cd156a7a
commit 54b1df69a9
2 changed files with 18 additions and 12 deletions

View File

@ -36,8 +36,7 @@ class Clock : public ALabel {
auto weekdays_header(const date::weekday& first_dow, std::ostream& os) -> void; auto weekdays_header(const date::weekday& first_dow, std::ostream& os) -> void;
auto first_day_of_week() -> date::weekday; auto first_day_of_week() -> date::weekday;
const date::time_zone* current_timezone(); const date::time_zone* current_timezone();
auto print_iso_weeknum(std::ostream& os, auto print_iso_weeknum(std::ostream& os, int weeknum) -> void;
int weeknum) -> void;
bool is_timezone_fixed(); bool is_timezone_fixed();
auto timezones_text(std::chrono::system_clock::time_point* now) -> std::string; auto timezones_text(std::chrono::system_clock::time_point* now) -> std::string;
}; };

View File

@ -1,7 +1,8 @@
#include "modules/clock.hpp" #include "modules/clock.hpp"
#include <iomanip>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <iomanip>
#if FMT_VERSION < 60000 #if FMT_VERSION < 60000
#include <fmt/time.h> #include <fmt/time.h>
#else #else
@ -167,10 +168,14 @@ auto waybar::modules::Clock::calendar_text(const waybar_time& wtime) -> std::str
std::stringstream os; std::stringstream os;
const auto first_dow = first_day_of_week(); const auto first_dow = first_day_of_week();
int ws{0}; // weeks-pos: side(1 - left, 2 - right) int ws{0}; // weeks-pos: side(1 - left, 2 - right)
int wn{0}; // weeknumber int wn{0}; // weeknumber
if (config_["calendar-weeks-pos"].isString()) { if (config_["calendar-weeks-pos"].isString()) {
wn = (date::sys_days{date::year_month_day{ym/1}} - date::sys_days{date::year_month_day{ymd.year()/1/1}}).count()/7+1; wn = (date::sys_days{date::year_month_day{ym / 1}} -
date::sys_days{date::year_month_day{ymd.year() / 1 / 1}})
.count() /
7 +
1;
if (config_["calendar-weeks-pos"].asString() == "left") { if (config_["calendar-weeks-pos"].asString() == "left") {
ws = 1; ws = 1;
// Add paddings before the header // Add paddings before the header
@ -179,7 +184,7 @@ auto waybar::modules::Clock::calendar_text(const waybar_time& wtime) -> std::str
ws = 2; ws = 2;
} }
} }
weekdays_header(first_dow, os); weekdays_header(first_dow, os);
/* Print weeknumber on the left for the first row*/ /* Print weeknumber on the left for the first row*/
if (ws == 1) { if (ws == 1) {
@ -221,7 +226,8 @@ auto waybar::modules::Clock::calendar_text(const waybar_time& wtime) -> std::str
} }
} else if (config_["format-calendar"].isString()) { } else if (config_["format-calendar"].isString()) {
os << fmt::format(config_["format-calendar"].asString(), date::format("%e", d)); os << fmt::format(config_["format-calendar"].asString(), date::format("%e", d));
} else os << date::format("%e", d); } else
os << date::format("%e", d);
/*Print weeks on the right when the endings with spaces*/ /*Print weeks on the right when the endings with spaces*/
if (ws == 2 && d == last_day && wd.c_encoding() < 6) { if (ws == 2 && d == last_day && wd.c_encoding() < 6) {
empty_days = 6 - wd.c_encoding(); empty_days = 6 - wd.c_encoding();
@ -257,7 +263,8 @@ auto waybar::modules::Clock::weekdays_header(const date::weekday& first_dow, std
if (config_["format-calendar-weekdays"].isString()) { if (config_["format-calendar-weekdays"].isString()) {
os << fmt::format(config_["format-calendar-weekdays"].asString(), res.str()); os << fmt::format(config_["format-calendar-weekdays"].asString(), res.str());
} else os << res.str(); } else
os << res.str();
} }
auto waybar::modules::Clock::timezones_text(std::chrono::system_clock::time_point* now) auto waybar::modules::Clock::timezones_text(std::chrono::system_clock::time_point* now)
@ -281,14 +288,14 @@ auto waybar::modules::Clock::timezones_text(std::chrono::system_clock::time_poin
return os.str(); return os.str();
} }
auto waybar::modules::Clock::print_iso_weeknum(std::ostream& os, auto waybar::modules::Clock::print_iso_weeknum(std::ostream& os, int weeknum) -> void {
int weeknum) -> void {
std::stringstream res; std::stringstream res;
res << 'W' << std::setfill('0') << std::setw(2) << weeknum; res << 'W' << std::setfill('0') << std::setw(2) << weeknum;
if (config_["format-calendar-weeks"].isString()) { if (config_["format-calendar-weeks"].isString()) {
os << fmt::format(config_["format-calendar-weeks"].asString(), res.str()); os << fmt::format(config_["format-calendar-weeks"].asString(), res.str());
} else os << res.str(); } else
os << res.str();
} }
#ifdef HAVE_LANGINFO_1STDAY #ifdef HAVE_LANGINFO_1STDAY