diff --git a/src/commands/CmdChart.cpp b/src/commands/CmdChart.cpp index a214761c..68847bc4 100644 --- a/src/commands/CmdChart.cpp +++ b/src/commands/CmdChart.cpp @@ -44,7 +44,7 @@ static std::string renderTotal (const std::string&, const Rules&, time static std::string renderSubTotal (const std::string&, const Rules&, int, int, time_t); static void renderExclusionBlocks (const std::string&, const Rules&, std::vector &, bool, const Datetime&, int, int, const std::vector &); static void renderInterval (const std::string&, const Rules&, std::vector &, const Datetime&, const Interval&, std::map &, int, time_t&, bool); - std::string renderHolidays (const std::string&, const Rules&, const Interval&); + std::string renderHolidays (const Rules &rules, const Interval &filter); static std::string renderSummary (const std::string&, const Interval&, const std::vector &, const std::vector &, bool); unsigned long getIndentSize (const std::string &type, const Rules &rules); @@ -216,8 +216,10 @@ int renderChart ( } const auto with_summary = rules.getBoolean ("reports." + type + ".summary"); + const auto with_holidays = rules.getBoolean ("reports." + type + ".holidays"); + std::cout << renderSubTotal (type, rules, first_hour, last_hour, total_work) - << renderHolidays (type, rules, filter) + << (with_holidays ? renderHolidays (rules, filter) : "") << (with_summary ? renderSummary (indent, filter, exclusions, tracked, blank) : ""); return 0; @@ -600,32 +602,32 @@ static void renderInterval ( //////////////////////////////////////////////////////////////////////////////// std::string renderHolidays ( - const std::string& type, const Rules& rules, const Interval& filter) { std::stringstream out; - if (rules.getBoolean ("reports." + type + ".holidays")) + auto holidays = rules.all ("holidays."); + + for (auto& entry : holidays) { - for (auto& entry : rules.all ("holidays.")) + auto first_dot = entry.find ('.'); + auto last_dot = entry.rfind ('.'); + + if (last_dot != std::string::npos) { - auto first_dot = entry.find ('.'); - auto last_dot = entry.rfind ('.'); - if (last_dot != std::string::npos) + auto date = entry.substr (last_dot + 1); + std::replace (date.begin (), date.end (), '_', '-'); + Datetime holiday (date); + + if (holiday >= filter.start && + holiday <= filter.end) { - auto date = entry.substr (last_dot + 1); - std::replace (date.begin (), date.end (), '_', '-'); - Datetime holiday (date); - if (holiday >= filter.start && - holiday <= filter.end) - { - out << Datetime (date).toString ("Y-M-D") - << " [" - << entry.substr (first_dot + 1, last_dot - first_dot - 1) - << "] " - << rules.get (entry) - << '\n'; - } + out << Datetime (date).toString ("Y-M-D") + << " [" + << entry.substr (first_dot + 1, last_dot - first_dot - 1) + << "] " + << rules.get (entry) + << '\n'; } } } diff --git a/src/commands/CmdSummary.cpp b/src/commands/CmdSummary.cpp index adad94c7..c544143c 100644 --- a/src/commands/CmdSummary.cpp +++ b/src/commands/CmdSummary.cpp @@ -33,7 +33,7 @@ #include // Implemented in CmdChart.cpp. -std::string renderHolidays (const std::string&, const Rules&, const Interval&); +std::string renderHolidays (const Rules &rules, const Interval &filter); //////////////////////////////////////////////////////////////////////////////// int CmdSummary ( @@ -177,9 +177,11 @@ int CmdSummary ( table.set (table.addRow (), (ids ? 8 : 7) + offset, " ", Color ("underline")); table.set (table.addRow (), (ids ? 8 : 7) + offset, Duration (grand_total).formatHours ()); + const auto with_holidays = rules.getBoolean ("reports.summary.holidays"); + std::cout << '\n' << table.render () - << renderHolidays ("summary", rules, filter) + << (with_holidays ? renderHolidays (rules, filter) : "") << '\n'; return 0;