From dff02d3d86ad47417717b90aeeafbc76c3acd011 Mon Sep 17 00:00:00 2001 From: Thomas Lauf Date: Thu, 22 Nov 2018 21:47:21 +0100 Subject: [PATCH] Let determineHourRange return a pair of ints - Defaults to (0, 23) --- src/commands/CmdChart.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/commands/CmdChart.cpp b/src/commands/CmdChart.cpp index 84ca3944..ecdc84ae 100644 --- a/src/commands/CmdChart.cpp +++ b/src/commands/CmdChart.cpp @@ -36,7 +36,7 @@ #include int renderChart (const CLI&, const std::string&, Interval&, Rules&, Database&); -static void determineHourRange (const std::string&, const Rules&, const Interval&, const std::vector &, int&, int&); +static std::pair determineHourRange (const std::string&, const Rules&, const Interval&, const std::vector &); static void renderAxis (const std::string&, const Rules&, bool, const std::string&, int, int); static std::string renderMonth (const std::string&, const Rules&, const Datetime&, const Datetime&); static std::string renderDayName (const std::string&, const Rules&, Datetime&, Color&, Color&); @@ -127,9 +127,10 @@ int renderChart ( Color colorHoliday (with_colors ? rules.get ("theme.colors.holiday") : ""); // Determine hours shown. - int first_hour = 0; - int last_hour = 23; - determineHourRange (type, rules, filter, tracked, first_hour, last_hour); + auto hour_range = determineHourRange (type, rules, filter, tracked); + + int first_hour = hour_range.first; + int last_hour = hour_range.second; auto indent = std::string (getIndentSize (type, rules), ' '); @@ -234,20 +235,18 @@ unsigned long getIndentSize (const std::string &type, const Rules &rules) //////////////////////////////////////////////////////////////////////////////// // Scan all tracked intervals, looking for the earliest and latest hour into // which an interval extends. -static void determineHourRange ( +static std::pair determineHourRange ( const std::string& type, const Rules& rules, const Interval& filter, - const std::vector & tracked, - int& first_hour, - int& last_hour) + const std::vector & tracked) { + // Default to the full day. + auto first_hour = 0; + auto last_hour = 23; + if (rules.get ("reports." + type + ".hours") == "auto") { - // Default to the full day. - first_hour = 0; - last_hour = 23; - // If there is no data, show the whole day. if (! tracked.empty ()) { @@ -288,9 +287,11 @@ static void determineHourRange ( last_hour = std::min (last_hour + 1, 23); } } - - debug (format ("Day range is from {1}:00 - {2}:00", first_hour, last_hour)); } + + debug (format ("Day range is from {1}:00 - {2}:00", first_hour, last_hour)); + + return std::make_pair (first_hour, last_hour); } ////////////////////////////////////////////////////////////////////////////////