Extract type from renderHolidays

This commit is contained in:
Thomas Lauf 2018-12-27 23:12:52 +01:00
parent 61aebb3b4e
commit 63d56a84d0
2 changed files with 27 additions and 23 deletions

View file

@ -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 <Composite>&, bool, const Datetime&, int, int, const std::vector <Range>&);
static void renderInterval (const std::string&, const Rules&, std::vector <Composite>&, const Datetime&, const Interval&, std::map <std::string, Color>&, 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 <Range>&, const std::vector <Interval>&, 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,22 +602,23 @@ 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"))
{
for (auto& entry : rules.all ("holidays."))
auto holidays = rules.all ("holidays.");
for (auto& entry : holidays)
{
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)
{
@ -628,7 +631,6 @@ std::string renderHolidays (
}
}
}
}
return out.str ();
}

View file

@ -33,7 +33,7 @@
#include <iostream>
// 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;