From c0fbfcc58cf7664063b296ee6933e40efa8725f6 Mon Sep 17 00:00:00 2001 From: Justin Forest Date: Mon, 17 Dec 2012 17:09:16 +0400 Subject: [PATCH] Display duration of each activity session --- src/commands/CmdInfo.cpp | 4 ++-- src/en-US.h | 1 + src/feedback.cpp | 12 +++++++++++- src/main.h | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/commands/CmdInfo.cpp b/src/commands/CmdInfo.cpp index aefe1eb12..3e3a0b43a 100644 --- a/src/commands/CmdInfo.cpp +++ b/src/commands/CmdInfo.cpp @@ -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") == "" diff --git a/src/en-US.h b/src/en-US.h index 101443694..793555864 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -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." diff --git a/src/feedback.cpp b/src/feedback.cpp index 7a24650bf..e28bcefbf 100644 --- a/src/feedback.cpp +++ b/src/feedback.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -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) diff --git a/src/main.h b/src/main.h index 10fc6afdc..6c48375bc 100644 --- a/src/main.h +++ b/src/main.h @@ -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);