ISSUE#2073

Signed-off-by: Viktar Lukashonak <myxabeer@gmail.com>
This commit is contained in:
Viktar Lukashonak 2023-04-13 17:16:03 +03:00
parent a46b8a0109
commit 6de3b58d6a
No known key found for this signature in database
GPG Key ID: 08A413AA87200A6F
2 changed files with 14 additions and 4 deletions

View File

@ -50,6 +50,7 @@ class Clock final : public ALabel {
date::months cldShift_{0};
std::string cldYearCached_{};
std::string cldMonCached_{};
date::day cldBaseDay_{0};
/*Calendar functions*/
auto get_calendar(const date::zoned_seconds& now, const date::zoned_seconds& wtime)
-> std::string;

View File

@ -93,9 +93,11 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
fmtMap_.insert({1, config_[kCalendarPlaceholder]["format"]["weekdays"].asString()});
else
fmtMap_.insert({1, "{}"});
if (config_[kCalendarPlaceholder]["format"]["today"].isString())
if (config_[kCalendarPlaceholder]["format"]["today"].isString()) {
fmtMap_.insert({3, config_[kCalendarPlaceholder]["format"]["today"].asString()});
else
cldBaseDay_ =
date::year_month_day{date::floor<date::days>(std::chrono::system_clock::now())}.day();
} else
fmtMap_.insert({3, "{}"});
if (config_[kCalendarPlaceholder]["mode"].isString()) {
const std::string cfgMode{(config_[kCalendarPlaceholder]["mode"].isString())
@ -315,6 +317,7 @@ auto waybar::modules::Clock::get_calendar(const date::zoned_seconds& now,
const auto ymd{date::year_month_day{daypoint}};
const auto ym{ymd.year() / ymd.month()};
const auto y{ymd.year()};
const auto d{ymd.day()};
const auto firstdow = first_day_of_week();
const auto maxRows{12 / cldMonCols_};
std::ostringstream os;
@ -325,13 +328,19 @@ auto waybar::modules::Clock::get_calendar(const date::zoned_seconds& now,
if (cldMode_ == CldMode::YEAR) {
if (y / date::month{1} / 1 == cldYearShift_)
return cldYearCached_;
if (d == cldBaseDay_ || (uint)cldBaseDay_ == 0u)
return cldYearCached_;
else
cldBaseDay_ = d;
else
cldYearShift_ = y / date::month{1} / 1;
}
if (cldMode_ == CldMode::MONTH) {
if (ym == cldMonShift_)
return cldMonCached_;
if (d == cldBaseDay_ || (uint)cldBaseDay_ == 0u)
return cldMonCached_;
else
cldBaseDay_ = d;
else
cldMonShift_ = ym;
}