diff --git a/src/Task.cpp b/src/Task.cpp index 5798515cb..2a7f39a4a 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -173,52 +173,24 @@ Task::status Task::textToStatus (const std::string& input) std::string Task::statusToText (Task::status s) { if (s == Task::pending) return "pending"; - else if (s == Task::completed) return "completed"; - else if (s == Task::deleted) return "deleted"; else if (s == Task::recurring) return "recurring"; else if (s == Task::waiting) return "waiting"; + else if (s == Task::completed) return "completed"; + else if (s == Task::deleted) return "deleted"; return "pending"; } //////////////////////////////////////////////////////////////////////////////// -void Task::setEntry () +void Task::setAsNow (const std::string& att) { char now[16]; sprintf (now, "%u", (unsigned int) time (NULL)); - set ("entry", now); + set (att, now); recalc_urgency = true; } -//////////////////////////////////////////////////////////////////////////////// -void Task::setEnd () -{ - char now[16]; - sprintf (now, "%u", (unsigned int) time (NULL)); - set ("end", now); - - recalc_urgency = true; -} - -//////////////////////////////////////////////////////////////////////////////// -void Task::setStart () -{ - char now[16]; - sprintf (now, "%u", (unsigned int) time (NULL)); - set ("start", now); - - recalc_urgency = true; -} - -//////////////////////////////////////////////////////////////////////////////// -void Task::setModified () -{ - char now[16]; - sprintf (now, "%u", (unsigned int) time (NULL)); - set ("modified", now); -} - //////////////////////////////////////////////////////////////////////////////// bool Task::has (const std::string& name) const { @@ -1485,16 +1457,16 @@ void Task::validate (bool applyDefault /* = true */) #ifdef PRODUCT_TASKWARRIOR // Provide an entry date unless user already specified one. if (!has ("entry") || get ("entry") == "") - setEntry (); + setAsNow ("entry"); // Completed tasks need an end date, so inherit the entry date. if ((status == Task::completed || status == Task::deleted) && (! has ("end") || get ("end") == "")) - setEnd (); + setAsNow ("end"); // Provide an entry date unless user already specified one. if (!has ("modified") || get ("modified") == "") - setModified (); + setAsNow ("modified"); if (applyDefault) { diff --git a/src/Task.h b/src/Task.h index ca0796b34..dd4644c89 100644 --- a/src/Task.h +++ b/src/Task.h @@ -90,11 +90,7 @@ public: static status textToStatus (const std::string&); static std::string statusToText (status); - void setEntry (); - void setEnd (); - void setStart (); - void setModified (); - + void setAsNow (const std::string&); bool has (const std::string&) const; std::vector all (); const std::string get (const std::string&) const; diff --git a/src/commands/CmdDelete.cpp b/src/commands/CmdDelete.cpp index 75ab2a481..178ddf5ce 100644 --- a/src/commands/CmdDelete.cpp +++ b/src/commands/CmdDelete.cpp @@ -87,7 +87,7 @@ int CmdDelete::execute (std::string& output) task->modify (Task::modAnnotate); task->setStatus (Task::deleted); if (! task->has ("end")) - task->setEnd (); + task->setAsNow ("end"); if (permission (*task, question, filtered.size ())) { @@ -112,7 +112,7 @@ int CmdDelete::execute (std::string& output) sibling->modify (Task::modAnnotate); sibling->setStatus (Task::deleted); if (! sibling->has ("end")) - sibling->setEnd (); + sibling->setAsNow ("end"); updateRecurrenceMask (*sibling); context.tdb2.modify (*sibling); @@ -126,7 +126,7 @@ int CmdDelete::execute (std::string& output) context.tdb2.get (task->get ("parent"), parent); parent.setStatus (Task::deleted); if (! parent.has ("end")) - parent.setEnd (); + parent.setAsNow ("end"); context.tdb2.modify (parent); } @@ -145,7 +145,7 @@ int CmdDelete::execute (std::string& output) child->modify (Task::modAnnotate); child->setStatus (Task::deleted); if (! child->has ("end")) - child->setEnd (); + child->setAsNow ("end"); updateRecurrenceMask (*child); context.tdb2.modify (*child); diff --git a/src/commands/CmdDone.cpp b/src/commands/CmdDone.cpp index cde965d34..5c19435bd 100644 --- a/src/commands/CmdDone.cpp +++ b/src/commands/CmdDone.cpp @@ -82,7 +82,7 @@ int CmdDone::execute (std::string& output) task->modify (Task::modAnnotate); task->setStatus (Task::completed); if (! task->has ("end")) - task->setEnd (); + task->setAsNow ("end"); // Stop the task, if started. if (task->has ("start")) diff --git a/src/commands/CmdStart.cpp b/src/commands/CmdStart.cpp index 380f50c04..079206412 100644 --- a/src/commands/CmdStart.cpp +++ b/src/commands/CmdStart.cpp @@ -78,7 +78,7 @@ int CmdStart::execute (std::string& output) task->id, task->get ("description")); task->modify (Task::modAnnotate); - task->setStart (); + task->setAsNow ("start"); if (context.config.getBoolean ("journal.time")) task->addAnnotation (context.config.get ("journal.time.start.annotation")); diff --git a/src/recur.cpp b/src/recur.cpp index e1b536850..18df1cdf6 100644 --- a/src/recur.cpp +++ b/src/recur.cpp @@ -93,7 +93,7 @@ void handleRecurrence () rec.id = context.tdb2.next_id (); // New ID. rec.set ("uuid", uuid ()); // New UUID. rec.set ("parent", t->get ("uuid")); // Remember mom. - rec.setEntry (); // New entry date. + rec.setAsNow ("entry"); // New entry date. char dueDate[16]; sprintf (dueDate, "%u", (unsigned int) d->toEpoch ());