From 5b75ba4571a5deb417958da9281df69db60fd956 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 29 May 2016 12:28:08 -0400 Subject: [PATCH] CmdChart: Added optional holiday table --- src/commands/CmdChart.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/commands/CmdChart.cpp b/src/commands/CmdChart.cpp index 94f7ff6d..472c66ec 100644 --- a/src/commands/CmdChart.cpp +++ b/src/commands/CmdChart.cpp @@ -46,6 +46,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 &, Palette&, const Datetime&, int, int, const std::vector &); static void renderInterval (const std::string&, const Rules&, std::vector &, const Datetime&, const Interval&, Palette&, std::map &, time_t&); +static std::string renderHolidays (const std::string&, const Rules&, const Interval&); static std::string renderSummary (const std::string&, const Rules&, const std::string&, const Interval&, const std::vector &, const std::vector &, bool); //////////////////////////////////////////////////////////////////////////////// @@ -204,6 +205,7 @@ int renderChart ( } std::cout << renderSubTotal (type, rules, first_hour, last_hour, total_work) + << renderHolidays (type, rules, filter) << renderSummary (type, rules, std::string (indent, ' '), filter, exclusions, tracked, blank); return 0; @@ -505,6 +507,33 @@ static void renderInterval ( } } +//////////////////////////////////////////////////////////////////////////////// +static std::string renderHolidays ( + const std::string& type, + const Rules& rules, + const Interval& filter) +{ + std::stringstream out; + if (rules.getBoolean ("reports." + type + ".holidays")) + { + for (auto& entry : rules.all ("holidays.")) + { + 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.range.start && + holiday <= filter.range.end) + out << Datetime (date).toString ("Y-M-D") << ' ' << rules.get (entry) << '\n'; + } + } + } + + return out.str (); +} + //////////////////////////////////////////////////////////////////////////////// static std::string renderSummary ( const std::string& type,