From c3baf8f119321ea0aa6e7a20a56239e22bf35f2c Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 21 May 2016 14:39:11 -0500 Subject: [PATCH] CmdChart: Parameterized total hours rendering --- src/commands/CmdChart.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/commands/CmdChart.cpp b/src/commands/CmdChart.cpp index 64822ae9..ad8450b1 100644 --- a/src/commands/CmdChart.cpp +++ b/src/commands/CmdChart.cpp @@ -41,6 +41,7 @@ int renderChart (const std::string&, Interval&, Rules&, static void renderAxis (const std::string&, const Rules&, Palette&, const std::string&, int, int); static std::string renderMonth (const Datetime&, const Datetime&); static std::string renderDayName (Datetime&, Color&); +static std::string renderTotal (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 void renderSummary (const std::string&, const Interval&, const std::vector &, const std::vector &); @@ -163,11 +164,7 @@ int renderChart ( } std::cout << " "; - - if (work) - std::cout << std::setw (3) << std::setfill (' ') << hours - << ':' - << std::setw (2) << std::setfill ('0') << minutes; + std::cout << renderTotal (work); std::cout << '\n'; previous = day; @@ -242,6 +239,22 @@ static std::string renderDayName (Datetime& day, Color& color) return out.str (); } +//////////////////////////////////////////////////////////////////////////////// +static std::string renderTotal (time_t work) +{ + std::stringstream out; + if (work) + { + int hours = work / 3600; + int minutes = (work % 3600) / 60; + std::cout << std::setw (3) << std::setfill (' ') << hours + << ':' + << std::setw (2) << std::setfill ('0') << minutes; + } + + return out.str (); +} + //////////////////////////////////////////////////////////////////////////////// static void renderExclusionBlocks ( const std::string& type,