From 792eab8621afbe0da65e5edaa7eaec46f5bdc172 Mon Sep 17 00:00:00 2001 From: Johannes Schlatow Date: Mon, 17 Jan 2011 15:21:55 +0100 Subject: [PATCH] Info report * added a line to the journal which shows the total time a task was active --- src/report.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/report.cpp b/src/report.cpp index 398a3ef9e..10088182b 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -708,6 +708,7 @@ int handleInfo (std::string& outs) std::string previous; std::string current; unsigned int i = 0; + long time = 0; while (i < undo.size ()) { when = undo[i++]; @@ -730,6 +731,20 @@ int handleInfo (std::string& outs) Task before (previous.substr (4)); Task after (current.substr (4)); journal.addCell (row, 1, taskInfoDifferences (before, after)); + + // calculate the total active time + if (before.get ("start") == "" + && after.get ("start") != "") + { + // task started + time -= timestamp.toEpoch(); + } + else if (before.get ("start") != "" + && after.get ("start") == "") + { + // task stopped + time += timestamp.toEpoch(); + } } } } @@ -737,6 +752,26 @@ int handleInfo (std::string& outs) if (journal.rowCount () > 0) out << journal.render () << "\n"; + + // add now() if task is still active + if (time < 0) + time += Date().toEpoch(); + + // print total active time + if (time >= 0) + { + int row = journal.addRow (); + int hours = time / 3600; + int minutes = (time % 3600) / 60; + + out << "Total active time: " + << hours << "h " << minutes; + + if (minutes == 0) + out << "0"; + + out << "m\n\n"; + } } }