CmdChart: Added optional holiday table

This commit is contained in:
Paul Beckingham 2016-05-29 12:28:08 -04:00
parent db79917bc1
commit 5b75ba4571

View file

@ -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 std::string renderSubTotal (const std::string&, const Rules&, int, int, time_t);
static void renderExclusionBlocks (const std::string&, const Rules&, std::vector <Composite>&, Palette&, const Datetime&, int, int, const std::vector <Range>&); static void renderExclusionBlocks (const std::string&, const Rules&, std::vector <Composite>&, Palette&, const Datetime&, int, int, const std::vector <Range>&);
static void renderInterval (const std::string&, const Rules&, std::vector <Composite>&, const Datetime&, const Interval&, Palette&, std::map <std::string, Color>&, time_t&); static void renderInterval (const std::string&, const Rules&, std::vector <Composite>&, const Datetime&, const Interval&, Palette&, std::map <std::string, Color>&, 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 <Range>&, const std::vector <Interval>&, bool); static std::string renderSummary (const std::string&, const Rules&, const std::string&, const Interval&, const std::vector <Range>&, const std::vector <Interval>&, bool);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -204,6 +205,7 @@ int renderChart (
} }
std::cout << renderSubTotal (type, rules, first_hour, last_hour, total_work) 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); << renderSummary (type, rules, std::string (indent, ' '), filter, exclusions, tracked, blank);
return 0; 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 ( static std::string renderSummary (
const std::string& type, const std::string& type,