From 7e2da42f405a8a852bdfedda5a9f9c3da1cfd350 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 17 Jun 2009 22:52:04 -0400 Subject: [PATCH] Bug Fix - due date, colorization - Fixed bug that caused colorization to be way, way off. Silly mistake. - Fixed bug whereby due dates and durations were stored as-is, but should have been converted. - On a related note, added Date::toEpochString, Duration::operator (std::string). --- src/Att.cpp | 4 +-- src/Context.cpp | 6 +---- src/Date.cpp | 9 +++++++ src/Date.h | 1 + src/Duration.cpp | 10 ++++++++ src/Duration.h | 1 + src/Filter.cpp | 2 -- src/TDB.cpp | 4 ++- src/custom.cpp | 65 ++++++++++++++++++++++-------------------------- 9 files changed, 57 insertions(+), 45 deletions(-) diff --git a/src/Att.cpp b/src/Att.cpp index 1efc606c1..9eaa4a497 100644 --- a/src/Att.cpp +++ b/src/Att.cpp @@ -343,13 +343,13 @@ bool Att::validNameValue ( name == "until") { if (value != "") - Date (value); + value = Date (value).toEpochString (); } else if (name == "recur") { if (value != "") - Duration (value); + value = (std::string) Duration (value); } else if (name == "limit") diff --git a/src/Context.cpp b/src/Context.cpp index be0ba51ef..995044247 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -523,21 +523,17 @@ void Context::autoFilter () header ("auto filter: " + att->first + ".startswith:" + att->second.value ()); } - // TODO Don't create a uuid for every task? // Every task has a unique uuid by default, and it shouldn't be included. // The mechanism for filtering on tags is +/-, not tags:foo which // means that there can only be one tag, "foo". else if (att->first != "uuid" && - att->first != "tags" && - att->first != "project") + att->first != "tags") { filter.push_back (att->second); header ("auto filter: " + att->first + ":" + att->second.value ()); } } - // TODO Include Annotations as part of the description? - // Include tagAdditions. foreach (tag, tagAdditions) { diff --git a/src/Date.cpp b/src/Date.cpp index d895f7a04..985c9643d 100644 --- a/src/Date.cpp +++ b/src/Date.cpp @@ -25,6 +25,7 @@ // //////////////////////////////////////////////////////////////////////////////// #include +#include #include #include #include @@ -209,6 +210,14 @@ time_t Date::toEpoch () return mT; } +//////////////////////////////////////////////////////////////////////////////// +std::string Date::toEpochString () +{ + std::stringstream epoch; + epoch << mT; + return epoch.str (); +} + //////////////////////////////////////////////////////////////////////////////// void Date::toEpoch (time_t& epoch) { diff --git a/src/Date.h b/src/Date.h index 70a167187..2f4bed1a8 100644 --- a/src/Date.h +++ b/src/Date.h @@ -44,6 +44,7 @@ public: void toEpoch (time_t&); time_t toEpoch (); + std::string toEpochString (); void toMDY (int&, int&, int&); const std::string toString (const std::string& format = "m/d/Y") const; static bool valid (const std::string&, const std::string& format = "m/d/Y"); diff --git a/src/Duration.cpp b/src/Duration.cpp index 7d6c5116c..a6f0d716b 100644 --- a/src/Duration.cpp +++ b/src/Duration.cpp @@ -25,6 +25,8 @@ // //////////////////////////////////////////////////////////////////////////////// +#include +#include #include #include #include "text.h" @@ -55,6 +57,14 @@ Duration::operator time_t () return mDays; } +//////////////////////////////////////////////////////////////////////////////// +Duration::operator std::string () +{ + std::stringstream s; + s << mDays; + return s.str (); +} + //////////////////////////////////////////////////////////////////////////////// bool Duration::operator< (const Duration& other) { diff --git a/src/Duration.h b/src/Duration.h index 133ede0f7..f8e4b0f68 100644 --- a/src/Duration.h +++ b/src/Duration.h @@ -41,6 +41,7 @@ public: operator int (); operator time_t (); + operator std::string (); bool valid (const std::string&) const; void parse (const std::string&); diff --git a/src/Filter.cpp b/src/Filter.cpp index efdab9a28..98a098d44 100644 --- a/src/Filter.cpp +++ b/src/Filter.cpp @@ -42,8 +42,6 @@ bool Filter::pass (const Record& record) const // but it doesn't match, fail. foreach (att, (*this)) { -// TODO std::cout << "Filter::pass " << att->name () << "=" << att->value () << std::endl; - // If the record doesn't have the attribute, match against a default one. // This is because "att" may contain a modifier like "name.not:X". if ((r = record.find (att->name ())) == record.end ()) diff --git a/src/TDB.cpp b/src/TDB.cpp index 0eab7439e..790f3006b 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -36,6 +36,8 @@ #include "TDB.h" #include "main.h" +extern Context context; + //////////////////////////////////////////////////////////////////////////////// // The ctor/dtor do nothing. // The lock/unlock methods hold the file open. @@ -175,7 +177,7 @@ int TDB::load (std::vector & tasks, Filter& filter) numberStatusClauses != numberSimpleStatusClauses) loadCompleted (tasks, filter); else - std::cout << "# TDB::load optimization short circuit" << std::endl; + context.header ("load optimization short circuit"); #else loadCompleted (tasks, filter); #endif diff --git a/src/custom.cpp b/src/custom.cpp index 3dc43cabb..64131f5d3 100644 --- a/src/custom.cpp +++ b/src/custom.cpp @@ -158,16 +158,15 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::right); - int row = 0; std::string entered; - foreach (task, tasks) + for (unsigned int row = 0; row < tasks.size(); ++row) { - entered = task->get ("entry"); + entered = tasks[row].get ("entry"); if (entered.length ()) { Date dt (::atoi (entered.c_str ())); entered = dt.toString (context.config.get ("dateformat", "m/d/Y")); - table.addCell (row++, columnCount, entered); + table.addCell (row, columnCount, entered); } } } @@ -178,16 +177,15 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::right); - int row = 0; std::string started; - foreach (task, tasks) + for (unsigned int row = 0; row < tasks.size(); ++row) { - started = task->get ("start"); + started = tasks[row].get ("start"); if (started.length ()) { Date dt (::atoi (started.c_str ())); started = dt.toString (context.config.get ("dateformat", "m/d/Y")); - table.addCell (row++, columnCount, started); + table.addCell (row, columnCount, started); } } } @@ -198,16 +196,15 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::right); - int row = 0; std::string started; - foreach (task, tasks) + for (unsigned int row = 0; row < tasks.size(); ++row) { - started = task->get ("end"); + started = tasks[row].get ("end"); if (started.length ()) { Date dt (::atoi (started.c_str ())); started = dt.toString (context.config.get ("dateformat", "m/d/Y")); - table.addCell (row++, columnCount, started); + table.addCell (row, columnCount, started); } } } @@ -232,18 +229,17 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::right); - int row = 0; std::string created; std::string age; Date now; - foreach (task, tasks) + for (unsigned int row = 0; row < tasks.size(); ++row) { - created = task->get ("entry"); + created = tasks[row].get ("entry"); if (created.length ()) { Date dt (::atoi (created.c_str ())); age = formatSeconds ((time_t) (now - dt)); - table.addCell (row++, columnCount, age); + table.addCell (row, columnCount, age); } } } @@ -254,18 +250,17 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::right); - int row = 0; std::string created; std::string age; Date now; - foreach (task, tasks) + for (unsigned int row = 0; row < tasks.size(); ++row) { - created = task->get ("entry"); + created = tasks[row].get ("entry"); if (created.length ()) { Date dt (::atoi (created.c_str ())); age = formatSecondsCompact ((time_t) (now - dt)); - table.addCell (row++, columnCount, age); + table.addCell (row, columnCount, age); } } } @@ -276,10 +271,9 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::left); - int row = 0; - foreach (task, tasks) - if (task->get ("start") != "") - table.addCell (row++, columnCount, "*"); + for (unsigned int row = 0; row < tasks.size(); ++row) + if (tasks[row].has ("start")) + table.addCell (row, columnCount, "*"); } else if (*col == "tags") @@ -327,9 +321,12 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::right); - int row = 0; - foreach (task, tasks) - table.addCell (row++, columnCount, task->get ("recur")); + for (unsigned int row = 0; row < tasks.size(); ++row) + { + std::string recur = tasks[row].get ("recur"); + if (recur != "") + table.addCell (row, columnCount, recur); + } } else if (*col == "recurrence_indicator") @@ -338,10 +335,9 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::right); - int row = 0; - foreach (task, tasks) - table.addCell (row++, columnCount, - task->get ("recur") != "" ? "R" : ""); + for (unsigned int row = 0; row < tasks.size(); ++row) + if (tasks[row].has ("recur")) + table.addCell (row, columnCount, "R"); } else if (*col == "tag_indicator") @@ -350,10 +346,9 @@ std::string handleCustomReport (const std::string& report) table.setColumnWidth (columnCount, Table::minimum); table.setColumnJustification (columnCount, Table::right); - int row = 0; - foreach (task, tasks) - table.addCell (row++, columnCount, - task->getTagCount () ? "+" : ""); + for (unsigned int row = 0; row < tasks.size(); ++row) + if (tasks[row].getTagCount ()) + table.addCell (row, columnCount, "+"); } // Common to all columns.