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).
This commit is contained in:
Paul Beckingham 2009-06-17 22:52:04 -04:00
parent f701f10234
commit 7e2da42f40
9 changed files with 57 additions and 45 deletions

View file

@ -343,13 +343,13 @@ bool Att::validNameValue (
name == "until") name == "until")
{ {
if (value != "") if (value != "")
Date (value); value = Date (value).toEpochString ();
} }
else if (name == "recur") else if (name == "recur")
{ {
if (value != "") if (value != "")
Duration (value); value = (std::string) Duration (value);
} }
else if (name == "limit") else if (name == "limit")

View file

@ -523,21 +523,17 @@ void Context::autoFilter ()
header ("auto filter: " + att->first + ".startswith:" + att->second.value ()); 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. // Every task has a unique uuid by default, and it shouldn't be included.
// The mechanism for filtering on tags is +/-<tag>, not tags:foo which // The mechanism for filtering on tags is +/-<tag>, not tags:foo which
// means that there can only be one tag, "foo". // means that there can only be one tag, "foo".
else if (att->first != "uuid" && else if (att->first != "uuid" &&
att->first != "tags" && att->first != "tags")
att->first != "project")
{ {
filter.push_back (att->second); filter.push_back (att->second);
header ("auto filter: " + att->first + ":" + att->second.value ()); header ("auto filter: " + att->first + ":" + att->second.value ());
} }
} }
// TODO Include Annotations as part of the description?
// Include tagAdditions. // Include tagAdditions.
foreach (tag, tagAdditions) foreach (tag, tagAdditions)
{ {

View file

@ -25,6 +25,7 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <iostream> #include <iostream>
#include <sstream>
#include <time.h> #include <time.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
@ -209,6 +210,14 @@ time_t Date::toEpoch ()
return mT; return mT;
} }
////////////////////////////////////////////////////////////////////////////////
std::string Date::toEpochString ()
{
std::stringstream epoch;
epoch << mT;
return epoch.str ();
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Date::toEpoch (time_t& epoch) void Date::toEpoch (time_t& epoch)
{ {

View file

@ -44,6 +44,7 @@ public:
void toEpoch (time_t&); void toEpoch (time_t&);
time_t toEpoch (); time_t toEpoch ();
std::string toEpochString ();
void toMDY (int&, int&, int&); void toMDY (int&, int&, int&);
const std::string toString (const std::string& format = "m/d/Y") const; 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"); static bool valid (const std::string&, const std::string& format = "m/d/Y");

View file

@ -25,6 +25,8 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <sstream>
#include <string>
#include <vector> #include <vector>
#include <stdlib.h> #include <stdlib.h>
#include "text.h" #include "text.h"
@ -55,6 +57,14 @@ Duration::operator time_t ()
return mDays; return mDays;
} }
////////////////////////////////////////////////////////////////////////////////
Duration::operator std::string ()
{
std::stringstream s;
s << mDays;
return s.str ();
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
bool Duration::operator< (const Duration& other) bool Duration::operator< (const Duration& other)
{ {

View file

@ -41,6 +41,7 @@ public:
operator int (); operator int ();
operator time_t (); operator time_t ();
operator std::string ();
bool valid (const std::string&) const; bool valid (const std::string&) const;
void parse (const std::string&); void parse (const std::string&);

View file

@ -42,8 +42,6 @@ bool Filter::pass (const Record& record) const
// but it doesn't match, fail. // but it doesn't match, fail.
foreach (att, (*this)) 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. // 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". // This is because "att" may contain a modifier like "name.not:X".
if ((r = record.find (att->name ())) == record.end ()) if ((r = record.find (att->name ())) == record.end ())

View file

@ -36,6 +36,8 @@
#include "TDB.h" #include "TDB.h"
#include "main.h" #include "main.h"
extern Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// The ctor/dtor do nothing. // The ctor/dtor do nothing.
// The lock/unlock methods hold the file open. // The lock/unlock methods hold the file open.
@ -175,7 +177,7 @@ int TDB::load (std::vector <Task>& tasks, Filter& filter)
numberStatusClauses != numberSimpleStatusClauses) numberStatusClauses != numberSimpleStatusClauses)
loadCompleted (tasks, filter); loadCompleted (tasks, filter);
else else
std::cout << "# TDB::load optimization short circuit" << std::endl; context.header ("load optimization short circuit");
#else #else
loadCompleted (tasks, filter); loadCompleted (tasks, filter);
#endif #endif

View file

@ -158,16 +158,15 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
int row = 0;
std::string entered; 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 ()) if (entered.length ())
{ {
Date dt (::atoi (entered.c_str ())); Date dt (::atoi (entered.c_str ()));
entered = dt.toString (context.config.get ("dateformat", "m/d/Y")); 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.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
int row = 0;
std::string started; 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 ()) if (started.length ())
{ {
Date dt (::atoi (started.c_str ())); Date dt (::atoi (started.c_str ()));
started = dt.toString (context.config.get ("dateformat", "m/d/Y")); 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.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
int row = 0;
std::string started; 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 ()) if (started.length ())
{ {
Date dt (::atoi (started.c_str ())); Date dt (::atoi (started.c_str ()));
started = dt.toString (context.config.get ("dateformat", "m/d/Y")); 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.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
int row = 0;
std::string created; std::string created;
std::string age; std::string age;
Date now; 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 ()) if (created.length ())
{ {
Date dt (::atoi (created.c_str ())); Date dt (::atoi (created.c_str ()));
age = formatSeconds ((time_t) (now - dt)); 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.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
int row = 0;
std::string created; std::string created;
std::string age; std::string age;
Date now; 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 ()) if (created.length ())
{ {
Date dt (::atoi (created.c_str ())); Date dt (::atoi (created.c_str ()));
age = formatSecondsCompact ((time_t) (now - dt)); 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.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::left); table.setColumnJustification (columnCount, Table::left);
int row = 0; for (unsigned int row = 0; row < tasks.size(); ++row)
foreach (task, tasks) if (tasks[row].has ("start"))
if (task->get ("start") != "") table.addCell (row, columnCount, "*");
table.addCell (row++, columnCount, "*");
} }
else if (*col == "tags") else if (*col == "tags")
@ -327,9 +321,12 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
int row = 0; for (unsigned int row = 0; row < tasks.size(); ++row)
foreach (task, tasks) {
table.addCell (row++, columnCount, task->get ("recur")); std::string recur = tasks[row].get ("recur");
if (recur != "")
table.addCell (row, columnCount, recur);
}
} }
else if (*col == "recurrence_indicator") else if (*col == "recurrence_indicator")
@ -338,10 +335,9 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
int row = 0; for (unsigned int row = 0; row < tasks.size(); ++row)
foreach (task, tasks) if (tasks[row].has ("recur"))
table.addCell (row++, columnCount, table.addCell (row, columnCount, "R");
task->get ("recur") != "" ? "R" : "");
} }
else if (*col == "tag_indicator") else if (*col == "tag_indicator")
@ -350,10 +346,9 @@ std::string handleCustomReport (const std::string& report)
table.setColumnWidth (columnCount, Table::minimum); table.setColumnWidth (columnCount, Table::minimum);
table.setColumnJustification (columnCount, Table::right); table.setColumnJustification (columnCount, Table::right);
int row = 0; for (unsigned int row = 0; row < tasks.size(); ++row)
foreach (task, tasks) if (tasks[row].getTagCount ())
table.addCell (row++, columnCount, table.addCell (row, columnCount, "+");
task->getTagCount () ? "+" : "");
} }
// Common to all columns. // Common to all columns.