mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
helper: Added intervalSummarize
This commit is contained in:
parent
cdaaddf46a
commit
e6a27b1f72
1 changed files with 47 additions and 0 deletions
|
@ -26,6 +26,8 @@
|
|||
|
||||
#include <cmake.h>
|
||||
#include <timew.h>
|
||||
#include <Duration.h>
|
||||
#include <sstream>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
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 ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue