From e6a27b1f721f1d8593b1373524f130e9e5b99813 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 28 Mar 2016 22:48:09 -0400 Subject: [PATCH] helper: Added intervalSummarize --- src/helper.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/helper.cpp b/src/helper.cpp index eea998f3..2c6d7556 100644 --- a/src/helper.cpp +++ b/src/helper.cpp @@ -26,6 +26,8 @@ #include #include +#include +#include //////////////////////////////////////////////////////////////////////////////// Color tagColor (const Rules& rules, const std::string& tag) @@ -39,3 +41,48 @@ Color tagColor (const Rules& rules, const std::string& tag) } //////////////////////////////////////////////////////////////////////////////// +std::string intervalSummarize (const Rules& rules, const Interval& interval) +{ + std::stringstream out; + + if (interval.isStarted ()) + { + if (interval.isEnded ()) + { + Duration dur (Datetime (interval.end ()) - Datetime (interval.start ())); + out << "Recorded interval from " + << interval.start ().toISOLocalExtended () + << " to " + << interval.end ().toISOLocalExtended () + << " (" + << dur.format () + << ")"; + } + else + { + Duration dur (Datetime () - interval.start ()); + out << "Active interval since " + << interval.start ().toISOLocalExtended (); + + if (dur.toTime_t () > 10) + out << " (" + << dur.format () + << ")"; + } + + // Colorize tags. + auto tags = interval.tags (); + if (tags.size ()) + { + out << ", tagged:"; + for (auto& tag : tags) + out << ' ' << tagColor (rules, tag).colorize (quoteIfNeeded (tag)); + } + + out << "\n"; + } + + return out.str (); +} + +////////////////////////////////////////////////////////////////////////////////