From 218bb3bc2bb607b5c2978696d24ddf3f32203454 Mon Sep 17 00:00:00 2001 From: Skirmantas Kligys Date: Sun, 2 Feb 2020 14:55:37 -0800 Subject: [PATCH] Simpify calendar generation, single loop handles both first week and subsequent weeks. --- src/modules/clock.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index e7193539..134288ce 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -61,21 +61,13 @@ std::string calendar_text(const waybar_time& wtime, const date::weekday& first_d if (empty_days > 0) { os << std::string(empty_days * 3 - 1, ' '); } - auto d = date::day(1); - do { - if (wd != first_dow) os << ' '; - if (d == curr_day) { - os << "" << date::format("%e", d) << ""; - } else { - os << date::format("%e", d); - } - ++d; - } while (++wd != first_dow); - - // Following weeks. auto last_day = (ym/date::literals::last).day(); - for ( ; d <= last_day; ++d, ++wd) { - os << ((wd == first_dow) ? '\n' : ' '); + for (auto d = date::day(1); d <= last_day; ++d, ++wd) { + if (wd != first_dow) { + os << ' '; + } else if (unsigned(d) != 1) { + os << '\n'; + } if (d == curr_day) { os << "" << date::format("%e", d) << ""; } else {