Display duration of each activity session

This commit is contained in:
Justin Forest 2012-12-17 17:09:16 +04:00 committed by Paul Beckingham
parent 745d24e124
commit c0fbfcc58c
4 changed files with 15 additions and 4 deletions

View file

@ -381,7 +381,7 @@ int CmdInfo::execute (std::string& output)
std::string previous;
std::string current;
unsigned int i = 0;
long total_time = 0;
long total_time = 0, last_timestamp = 0;
while (i < undo.size ())
{
when = undo[i++];
@ -403,7 +403,7 @@ int CmdInfo::execute (std::string& output)
Task before (previous.substr (4));
Task after (current.substr (4));
journal.set (row, 1, taskInfoDifferences (before, after, dateformat));
journal.set (row, 1, taskInfoDifferences (before, after, dateformat, last_timestamp, timestamp.toEpoch()));
// calculate the total active time
if (before.get ("start") == ""

View file

@ -713,6 +713,7 @@
#define STRING_FEEDBACK_ATT_SET "{1} will be set to '{2}'."
#define STRING_FEEDBACK_ATT_MOD "{1} will be changed from '{2}' to '{3}'."
#define STRING_FEEDBACK_ATT_DEL "{1} deleted."
#define STRING_FEEDBACK_ATT_DEL_DUR "{1} deleted (duration: {2})."
#define STRING_FEEDBACK_ATT_WAS_SET "{1} set to '{2}'."
#define STRING_FEEDBACK_ATT_WAS_MOD "{1} changed from '{2}' to '{3}'."
#define STRING_FEEDBACK_ANN_ADD "Annotation of '{1}' added."

View file

@ -35,6 +35,7 @@
#include <stdlib.h>
#include <inttypes.h>
#include <Context.h>
#include <Duration.h>
#include <main.h>
#include <text.h>
#include <util.h>
@ -168,7 +169,7 @@ std::string taskDifferences (const Task& before, const Task& after)
}
////////////////////////////////////////////////////////////////////////////////
std::string taskInfoDifferences (const Task& before, const Task& after, const std::string& dateformat)
std::string taskInfoDifferences (const Task& before, const Task& after, const std::string& dateformat, long& last_timestamp, const long current_timestamp)
{
// Attributes are all there is, so figure the different attribute names
// between before and after.
@ -205,6 +206,11 @@ std::string taskInfoDifferences (const Task& before, const Task& after, const st
out << format (STRING_FEEDBACK_ANN_DEL, before.get (*name))
<< "\n";
}
else if (*name == "start") {
out << format (STRING_FEEDBACK_ATT_DEL_DUR, ucFirst (*name),
Duration(current_timestamp - last_timestamp).formatPrecise())
<< "\n";
}
else
{
out << format (STRING_FEEDBACK_ATT_DEL, ucFirst (*name))
@ -230,10 +236,14 @@ std::string taskInfoDifferences (const Task& before, const Task& after, const st
<< "\n";
}
else
{
if (*name == "start")
last_timestamp = current_timestamp;
out << format (STRING_FEEDBACK_ATT_WAS_SET,
ucFirst (*name),
renderAttribute (*name, after.get (*name), dateformat))
<< "\n";
}
}
for (name = beforeAtts.begin (); name != beforeAtts.end (); ++name)

View file

@ -69,7 +69,7 @@ void dependencyChainOnModify (Task&, Task&);
// feedback.cpp
bool taskDiff (const Task&, const Task&);
std::string taskDifferences (const Task&, const Task&);
std::string taskInfoDifferences (const Task&, const Task&, const std::string&);
std::string taskInfoDifferences (const Task&, const Task&, const std::string&, long&, const long);
std::string renderAttribute (const std::string&, const std::string&, const std::string& format = "");
void feedback_affected (const std::string&);
void feedback_affected (const std::string&, int);