mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Also refactor ghistory
This commit is contained in:
parent
4f6c3afa3e
commit
9bf0bf7a39
2 changed files with 267 additions and 451 deletions
|
@ -39,6 +39,16 @@ class CmdHistoryBase : public Command
|
|||
public:
|
||||
CmdHistoryBase ();
|
||||
int execute (std::string&);
|
||||
|
||||
private:
|
||||
std::map <time_t, int> groups; // Represents any timeinterval with data
|
||||
std::map <time_t, int> addedGroup; // Additions by timeinterval
|
||||
std::map <time_t, int> completedGroup; // Completions by timeinterval
|
||||
std::map <time_t, int> deletedGroup; // Deletions by timeinterval
|
||||
int rc;
|
||||
|
||||
void outputTabular(std::string&);
|
||||
void outputGraphical(std::string&);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////i
|
||||
|
@ -73,12 +83,52 @@ public:
|
|||
static constexpr const char * usage = "task <filter> history.monthly";
|
||||
static constexpr const char * description = STRING_CMD_HISTORY_USAGE_M;
|
||||
static constexpr unsigned int dateFieldCount = 2;
|
||||
static constexpr bool graphical = false;
|
||||
};
|
||||
|
||||
typedef CmdHistoryBase<MonthlyHistoryStrategy> CmdHistoryMonthly;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////i
|
||||
class MonthlyGHistoryStrategy {
|
||||
public:
|
||||
static Datetime getRelevantDate (const Datetime & dt) {
|
||||
return dt.startOfMonth ();
|
||||
}
|
||||
|
||||
static void setupTableDates (Table & view) {
|
||||
view.add (STRING_CMD_HISTORY_YEAR);
|
||||
view.add (STRING_CMD_HISTORY_MONTH);
|
||||
}
|
||||
|
||||
static void insertRowDate (Table & view, int row, time_t rowTime, time_t lastTime) {
|
||||
Datetime dt (rowTime);
|
||||
int m, d, y;
|
||||
dt.toYMD (y, m, d);
|
||||
|
||||
Datetime last_dt (lastTime);
|
||||
int last_m, last_d, last_y;
|
||||
last_dt.toYMD (last_y, last_m, last_d);
|
||||
|
||||
if (y != last_y)
|
||||
{
|
||||
view.set (row, 0, y);
|
||||
}
|
||||
view.set (row, 1, Datetime::monthName(m));
|
||||
}
|
||||
|
||||
static constexpr const char * keyword = "ghistory.monthly";
|
||||
static constexpr const char * usage = "task <filter> ghistory.monthly";
|
||||
static constexpr const char * description = STRING_CMD_GHISTORY_USAGE_M;
|
||||
static constexpr unsigned int dateFieldCount = 2;
|
||||
static constexpr bool graphical = true;
|
||||
};
|
||||
|
||||
typedef CmdHistoryBase<MonthlyGHistoryStrategy> CmdGHistoryMonthly;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////i
|
||||
class AnnualHistoryStrategy {
|
||||
public:
|
||||
|
@ -109,24 +159,47 @@ public:
|
|||
static constexpr const char * usage = "task <filter> history.annual";
|
||||
static constexpr const char * description = STRING_CMD_HISTORY_USAGE_A;
|
||||
static constexpr unsigned int dateFieldCount = 1;
|
||||
static constexpr bool graphical = false;
|
||||
};
|
||||
|
||||
typedef CmdHistoryBase<AnnualHistoryStrategy> CmdHistoryAnnual;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CmdGHistoryMonthly : public Command
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////i
|
||||
class AnnualGHistoryStrategy {
|
||||
public:
|
||||
CmdGHistoryMonthly ();
|
||||
int execute (std::string&);
|
||||
static Datetime getRelevantDate (const Datetime & dt) {
|
||||
return dt.startOfYear ();
|
||||
}
|
||||
|
||||
static void setupTableDates (Table & view) {
|
||||
view.add (STRING_CMD_HISTORY_YEAR);
|
||||
}
|
||||
|
||||
static void insertRowDate (Table & view, int row, time_t rowTime, time_t lastTime) {
|
||||
Datetime dt (rowTime);
|
||||
int m, d, y;
|
||||
dt.toYMD (y, m, d);
|
||||
|
||||
Datetime last_dt (lastTime);
|
||||
int last_m, last_d, last_y;
|
||||
last_dt.toYMD (last_y, last_m, last_d);
|
||||
|
||||
if (y != last_y)
|
||||
{
|
||||
view.set (row, 0, y);
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr const char * keyword = "ghistory.annual";
|
||||
static constexpr const char * usage = "task <filter> ghistory.annual";
|
||||
static constexpr const char * description = STRING_CMD_GHISTORY_USAGE_A;
|
||||
static constexpr unsigned int dateFieldCount = 1;
|
||||
static constexpr bool graphical = true;
|
||||
};
|
||||
|
||||
class CmdGHistoryAnnual : public Command
|
||||
{
|
||||
public:
|
||||
CmdGHistoryAnnual ();
|
||||
int execute (std::string&);
|
||||
};
|
||||
typedef CmdHistoryBase<AnnualGHistoryStrategy> CmdGHistoryAnnual;
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue