mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Code Cleanup
- Migrated the recur.cpp getDueState() function into Task::getDateState(), which can assess any date attribute. - Improved implementation to distinguish between: - not due, or not due for rc.due days - due after today - due later today - due earlier today - due before today This greater precision should address some outstanding issues.
This commit is contained in:
parent
5706cca207
commit
c933ed2cf7
6 changed files with 68 additions and 88 deletions
46
src/Task.cpp
46
src/Task.cpp
|
@ -323,6 +323,40 @@ void Task::setStatus (Task::status status)
|
||||||
recalc_urgency = true;
|
recalc_urgency = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Determines status of a date attribute.
|
||||||
|
Task::dateState Task::getDateState (const std::string& name) const
|
||||||
|
{
|
||||||
|
std::string value = get (name);
|
||||||
|
if (value.length ())
|
||||||
|
{
|
||||||
|
Date reference (value);
|
||||||
|
Date now;
|
||||||
|
Date today ("today");
|
||||||
|
|
||||||
|
if (reference < today)
|
||||||
|
return dateBeforeToday;
|
||||||
|
|
||||||
|
if (reference.sameDay (now))
|
||||||
|
{
|
||||||
|
if (reference < now)
|
||||||
|
return dateEarlierToday;
|
||||||
|
else
|
||||||
|
return dateLaterToday;
|
||||||
|
}
|
||||||
|
|
||||||
|
int imminentperiod = context.config.getInteger ("due");
|
||||||
|
if (imminentperiod == 0)
|
||||||
|
return dateAfterToday;
|
||||||
|
|
||||||
|
Date imminentDay = today + imminentperiod * 86400;
|
||||||
|
if (reference < imminentDay)
|
||||||
|
return dateAfterToday;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dateNotDue;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef PRODUCT_TASKWARRIOR
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Ready means pending, not blocked and either not scheduled or scheduled before
|
// Ready means pending, not blocked and either not scheduled or scheduled before
|
||||||
|
@ -345,7 +379,9 @@ bool Task::is_due () const
|
||||||
if (status != Task::completed &&
|
if (status != Task::completed &&
|
||||||
status != Task::deleted)
|
status != Task::deleted)
|
||||||
{
|
{
|
||||||
if (getDueState (get ("due")) == 1)
|
Task::dateState state = getDateState ("due");
|
||||||
|
if (state == dateAfterToday ||
|
||||||
|
state == dateLaterToday)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -381,7 +417,9 @@ bool Task::is_duetoday () const
|
||||||
if (status != Task::completed &&
|
if (status != Task::completed &&
|
||||||
status != Task::deleted)
|
status != Task::deleted)
|
||||||
{
|
{
|
||||||
if (getDueState (get ("due")) == 2)
|
Task::dateState state = getDateState ("due");
|
||||||
|
if (state == dateEarlierToday ||
|
||||||
|
state == dateLaterToday)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -479,7 +517,9 @@ bool Task::is_overdue () const
|
||||||
if (status != Task::completed &&
|
if (status != Task::completed &&
|
||||||
status != Task::deleted)
|
status != Task::deleted)
|
||||||
{
|
{
|
||||||
if (getDueState (get ("due")) == 3)
|
Task::dateState state = getDateState ("due");
|
||||||
|
if (state == dateEarlierToday ||
|
||||||
|
state == dateBeforeToday)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,9 @@ public:
|
||||||
// Status values.
|
// Status values.
|
||||||
enum status {pending, completed, deleted, recurring, waiting};
|
enum status {pending, completed, deleted, recurring, waiting};
|
||||||
|
|
||||||
|
// Date state values.
|
||||||
|
enum dateState {dateNotDue, dateAfterToday, dateLaterToday, dateEarlierToday, dateBeforeToday};
|
||||||
|
|
||||||
// Public data.
|
// Public data.
|
||||||
int id;
|
int id;
|
||||||
float urgency_value;
|
float urgency_value;
|
||||||
|
@ -117,6 +120,8 @@ public:
|
||||||
status getStatus () const;
|
status getStatus () const;
|
||||||
void setStatus (status);
|
void setStatus (status);
|
||||||
|
|
||||||
|
dateState getDateState (const std::string&) const;
|
||||||
|
|
||||||
int getTagCount () const;
|
int getTagCount () const;
|
||||||
bool hasTag (const std::string&) const;
|
bool hasTag (const std::string&) const;
|
||||||
void addTag (const std::string&);
|
void addTag (const std::string&);
|
||||||
|
|
|
@ -561,23 +561,24 @@ std::string CmdCalendar::renderMonths (
|
||||||
duedmy.month () == months[mpl] &&
|
duedmy.month () == months[mpl] &&
|
||||||
duedmy.year () == years[mpl])
|
duedmy.year () == years[mpl])
|
||||||
{
|
{
|
||||||
switch (getDueState (due))
|
switch (task->getDateState ("due"))
|
||||||
{
|
{
|
||||||
case 1: // imminent
|
case Task::dateNotDue:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Task::dateAfterToday:
|
||||||
cellColor.blend (color_due);
|
cellColor.blend (color_due);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: // today
|
case Task::dateEarlierToday:
|
||||||
|
case Task::dateLaterToday:
|
||||||
|
cellColor.blend (color_duetoday);
|
||||||
cellColor.blend (color_duetoday);
|
cellColor.blend (color_duetoday);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3: // overdue
|
case Task::dateBeforeToday:
|
||||||
cellColor.blend (color_overdue);
|
cellColor.blend (color_overdue);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0: // not due at all
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,8 +43,6 @@ void handleRecurrence ();
|
||||||
Date getNextRecurrence (Date&, std::string&);
|
Date getNextRecurrence (Date&, std::string&);
|
||||||
bool generateDueDates (Task&, std::vector <Date>&);
|
bool generateDueDates (Task&, std::vector <Date>&);
|
||||||
void updateRecurrenceMask (Task&);
|
void updateRecurrenceMask (Task&);
|
||||||
int getDueState (const std::string&);
|
|
||||||
int getDueState (const Date&);
|
|
||||||
bool nag (Task&);
|
bool nag (Task&);
|
||||||
|
|
||||||
// rules.cpp
|
// rules.cpp
|
||||||
|
|
|
@ -382,71 +382,6 @@ void updateRecurrenceMask (Task& task)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Determines whether a task is overdue. Returns
|
|
||||||
// 0 = not due at all
|
|
||||||
// 1 = imminent
|
|
||||||
// 2 = today
|
|
||||||
// 3 = overdue
|
|
||||||
int getDueState (const std::string& due)
|
|
||||||
{
|
|
||||||
if (due.length ())
|
|
||||||
{
|
|
||||||
Date dt (::atoi (due.c_str ()));
|
|
||||||
|
|
||||||
// rightNow is the current date + time.
|
|
||||||
static Date rightNow;
|
|
||||||
Date thisDay (rightNow.month (), rightNow.day (), rightNow.year ());
|
|
||||||
|
|
||||||
if (dt < rightNow)
|
|
||||||
return 3;
|
|
||||||
|
|
||||||
if (rightNow.sameDay (dt))
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
int imminentperiod = context.config.getInteger ("due");
|
|
||||||
|
|
||||||
if (imminentperiod == 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
Date imminentDay = thisDay + imminentperiod * 86400;
|
|
||||||
if (dt < imminentDay)
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Determines whether a task is overdue. Returns
|
|
||||||
// 0 = not due at all
|
|
||||||
// 1 = imminent
|
|
||||||
// 2 = today
|
|
||||||
// 3 = overdue
|
|
||||||
int getDueState (const Date& due)
|
|
||||||
{
|
|
||||||
// rightNow is the current date + time.
|
|
||||||
static Date rightNow;
|
|
||||||
Date thisDay (rightNow.month (), rightNow.day (), rightNow.year ());
|
|
||||||
|
|
||||||
if (due < rightNow)
|
|
||||||
return 3;
|
|
||||||
|
|
||||||
if (rightNow.sameDay (due))
|
|
||||||
return 2;
|
|
||||||
|
|
||||||
int imminentperiod = context.config.getInteger ("due");
|
|
||||||
|
|
||||||
if (imminentperiod == 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
Date imminentDay = thisDay + imminentperiod * 86400;
|
|
||||||
if (due < imminentDay)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Returns a Boolean indicator as to whether a nag message was generated, so
|
// Returns a Boolean indicator as to whether a nag message was generated, so
|
||||||
// that commands can control the number of nag messages displayed (ie one is
|
// that commands can control the number of nag messages displayed (ie one is
|
||||||
|
@ -477,7 +412,7 @@ bool nag (Task& task)
|
||||||
{
|
{
|
||||||
if (t->id == task.id)
|
if (t->id == task.id)
|
||||||
{
|
{
|
||||||
if (getDueState (t->get ("due")) == 3)
|
if (t->getDateState ("due") == Task::dateBeforeToday)
|
||||||
isOverdue = true;
|
isOverdue = true;
|
||||||
|
|
||||||
std::string priority = t->get ("priority");
|
std::string priority = t->get ("priority");
|
||||||
|
@ -486,7 +421,7 @@ bool nag (Task& task)
|
||||||
}
|
}
|
||||||
else if (t->getStatus () == Task::pending)
|
else if (t->getStatus () == Task::pending)
|
||||||
{
|
{
|
||||||
if (getDueState (t->get ("due")) == 3)
|
if (t->getDateState ("due") == Task::dateBeforeToday)
|
||||||
overdue++;
|
overdue++;
|
||||||
|
|
||||||
std::string priority = t->get ("priority");
|
std::string priority = t->get ("priority");
|
||||||
|
|
|
@ -222,7 +222,7 @@ static void colorizeDue (Task& task, const Color& base, Color& c)
|
||||||
Task::status status = task.getStatus ();
|
Task::status status = task.getStatus ();
|
||||||
if (status != Task::completed &&
|
if (status != Task::completed &&
|
||||||
status != Task::deleted &&
|
status != Task::deleted &&
|
||||||
getDueState (task.get ("due")) == 1)
|
task.getDateState ("due") == Task::dateAfterToday)
|
||||||
c.blend (base);
|
c.blend (base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,9 +233,10 @@ static void colorizeDueToday (Task& task, const Color& base, Color& c)
|
||||||
if (task.has ("due"))
|
if (task.has ("due"))
|
||||||
{
|
{
|
||||||
Task::status status = task.getStatus ();
|
Task::status status = task.getStatus ();
|
||||||
|
Task::dateState dateState = task.getDateState ("due");
|
||||||
if (status != Task::completed &&
|
if (status != Task::completed &&
|
||||||
status != Task::deleted &&
|
status != Task::deleted &&
|
||||||
getDueState (task.get ("due")) == 2)
|
(dateState == Task::dateLaterToday || dateState == Task::dateEarlierToday))
|
||||||
c.blend (base);
|
c.blend (base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,7 +249,7 @@ static void colorizeOverdue (Task& task, const Color& base, Color& c)
|
||||||
Task::status status = task.getStatus ();
|
Task::status status = task.getStatus ();
|
||||||
if (status != Task::completed &&
|
if (status != Task::completed &&
|
||||||
status != Task::deleted &&
|
status != Task::deleted &&
|
||||||
getDueState (task.get ("due")) == 3)
|
task.getDateState ("due") == Task::dateBeforeToday)
|
||||||
c.blend (base);
|
c.blend (base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue