mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Enhancement
- Implemented Record::get_date to eliminated the need to obtain a date as a string, then convert to time_t, then instantiate a Date.
This commit is contained in:
parent
7d5f4fdfc7
commit
63f91c2f88
12 changed files with 54 additions and 42 deletions
|
@ -168,6 +168,16 @@ unsigned long Record::get_ulong (const std::string& name) const
|
|||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
time_t Record::get_date (const std::string& name) const
|
||||
{
|
||||
Record::const_iterator i = this->find (name);
|
||||
if (i != this->end ())
|
||||
return (time_t) strtoul (i->second.value ().c_str (), NULL, 10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Record::set (const std::string& name, const std::string& value)
|
||||
{
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <Att.h>
|
||||
|
||||
class Record : public std::map <std::string, Att>
|
||||
|
@ -49,6 +50,7 @@ public:
|
|||
const std::string get (const std::string&) const;
|
||||
int get_int (const std::string&) const;
|
||||
unsigned long get_ulong (const std::string&) const;
|
||||
time_t get_date (const std::string&) const;
|
||||
void set (const std::string&, const std::string&);
|
||||
void set (const std::string&, int);
|
||||
void remove (const std::string&);
|
||||
|
|
|
@ -650,7 +650,7 @@ int TDB::gc ()
|
|||
else if (s == Task::waiting)
|
||||
{
|
||||
// Wake up tasks that need to be woken.
|
||||
Date wait_date (atoi (task->get ("wait").c_str ()));
|
||||
Date wait_date (task->get_date ("wait"));
|
||||
if (now > wait_date)
|
||||
{
|
||||
task->setStatus (Task::pending);
|
||||
|
|
|
@ -891,7 +891,7 @@ int TDB::gc ()
|
|||
else if (s == Task::waiting)
|
||||
{
|
||||
// Wake up tasks that need to be woken.
|
||||
Date wait_date (atoi (task->get ("wait").c_str ()));
|
||||
Date wait_date (task->get_date ("wait"));
|
||||
if (now > wait_date)
|
||||
{
|
||||
task->setStatus (Task::pending);
|
||||
|
|
12
src/Task.cpp
12
src/Task.cpp
|
@ -883,28 +883,28 @@ void Task::validate () const
|
|||
|
||||
if (has ("due"))
|
||||
{
|
||||
Date due (::atoi (get ("due").c_str ()));
|
||||
Date due (get_date ("due"));
|
||||
|
||||
// Verify wait < due
|
||||
if (has ("wait"))
|
||||
{
|
||||
Date wait (::atoi (get ("wait").c_str ()));
|
||||
Date wait (get_date ("wait"));
|
||||
if (wait > due)
|
||||
throw std::string (STRING_TASK_VALID_WAIT);
|
||||
}
|
||||
|
||||
Date entry (::atoi (get ("entry").c_str ()));
|
||||
Date entry (get_date ("entry"));
|
||||
|
||||
if (has ("start"))
|
||||
{
|
||||
Date start (::atoi (get ("start").c_str ()));
|
||||
Date start (get_date ("start"));
|
||||
if (entry > start)
|
||||
throw std::string (STRING_TASK_VALID_START);
|
||||
}
|
||||
|
||||
if (has ("end"))
|
||||
{
|
||||
Date end (::atoi (get ("end").c_str ()));
|
||||
Date end (get_date ("end"));
|
||||
if (entry > end)
|
||||
throw std::string (STRING_TASK_VALID_END);
|
||||
}
|
||||
|
@ -1129,7 +1129,7 @@ float Task::urgency ()
|
|||
if (has ("due"))
|
||||
{
|
||||
Date now;
|
||||
Date due (get ("due"));
|
||||
Date due (get_date ("due"));
|
||||
int days_overdue = (now - due) / 86400;
|
||||
|
||||
if (days_overdue >= 7) term = 1.0;
|
||||
|
|
|
@ -227,7 +227,7 @@ void Chart::scan (std::vector <Task>& tasks)
|
|||
for (task = tasks.begin (); task != tasks.end (); ++task)
|
||||
{
|
||||
// The entry date is when the counting starts.
|
||||
Date from = quantize (Date (task->get ("entry")));
|
||||
Date from = quantize (Date (task->get_date ("entry")));
|
||||
epoch = from.toEpoch ();
|
||||
|
||||
if (bars.find (epoch) != bars.end ())
|
||||
|
@ -241,7 +241,7 @@ void Chart::scan (std::vector <Task>& tasks)
|
|||
{
|
||||
if (task->has ("start"))
|
||||
{
|
||||
Date start = quantize (Date (task->get ("start")));
|
||||
Date start = quantize (Date (task->get_date ("start")));
|
||||
while (from < start)
|
||||
{
|
||||
epoch = from.toEpoch ();
|
||||
|
@ -272,7 +272,7 @@ void Chart::scan (std::vector <Task>& tasks)
|
|||
else if (status == Task::completed)
|
||||
{
|
||||
// Truncate history so it starts at 'earliest' for completed tasks.
|
||||
Date end = quantize (Date (task->get ("end")));
|
||||
Date end = quantize (Date (task->get_date ("end")));
|
||||
epoch = end.toEpoch ();
|
||||
|
||||
if (bars.find (epoch) != bars.end ())
|
||||
|
@ -288,7 +288,7 @@ void Chart::scan (std::vector <Task>& tasks)
|
|||
|
||||
if (task->has ("start"))
|
||||
{
|
||||
Date start = quantize (Date (task->get ("start")));
|
||||
Date start = quantize (Date (task->get_date ("start")));
|
||||
while (from < start)
|
||||
{
|
||||
epoch = from.toEpoch ();
|
||||
|
@ -312,7 +312,7 @@ void Chart::scan (std::vector <Task>& tasks)
|
|||
}
|
||||
else
|
||||
{
|
||||
Date end = quantize (Date (task->get ("end")));
|
||||
Date end = quantize (Date (task->get_date ("end")));
|
||||
while (from < end)
|
||||
{
|
||||
epoch = from.toEpoch ();
|
||||
|
@ -334,7 +334,7 @@ void Chart::scan (std::vector <Task>& tasks)
|
|||
else if (status == Task::deleted)
|
||||
{
|
||||
// Skip old deleted tasks.
|
||||
Date end = quantize (Date (task->get ("end")));
|
||||
Date end = quantize (Date (task->get_date ("end")));
|
||||
epoch = end.toEpoch ();
|
||||
if (bars.find (epoch) != bars.end ())
|
||||
++bars[epoch].removed;
|
||||
|
@ -344,7 +344,7 @@ void Chart::scan (std::vector <Task>& tasks)
|
|||
|
||||
if (task->has ("start"))
|
||||
{
|
||||
Date start = quantize (Date (task->get ("start")));
|
||||
Date start = quantize (Date (task->get_date ("start")));
|
||||
while (from < start)
|
||||
{
|
||||
epoch = from.toEpoch ();
|
||||
|
@ -361,7 +361,7 @@ void Chart::scan (std::vector <Task>& tasks)
|
|||
}
|
||||
else
|
||||
{
|
||||
Date end = quantize (Date (task->get ("end")));
|
||||
Date end = quantize (Date (task->get_date ("end")));
|
||||
while (from < end)
|
||||
{
|
||||
epoch = from.toEpoch ();
|
||||
|
|
|
@ -197,7 +197,7 @@ int CmdCalendar::execute (std::string& output)
|
|||
!task->hasTag ("nocal"))
|
||||
{
|
||||
++countDueDates;
|
||||
Date d (strtol (task->get ("due").c_str (), NULL, 10));
|
||||
Date d (task->get ("due"));
|
||||
if (d < oldest) oldest = d;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -296,7 +296,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
|
|||
{
|
||||
Date edited (strtol (value.c_str (), NULL, 10));
|
||||
|
||||
Date original (strtol (task.get ("entry").c_str (), NULL, 10));
|
||||
Date original (task.get_date ("entry"));
|
||||
if (!original.sameDay (edited))
|
||||
{
|
||||
context.footnote ("Creation date modified.");
|
||||
|
@ -314,7 +314,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
|
|||
|
||||
if (task.get ("start") != "")
|
||||
{
|
||||
Date original (strtol (task.get ("start").c_str (), NULL, 10));
|
||||
Date original (task.get_date ("start"));
|
||||
if (!original.sameDay (edited))
|
||||
{
|
||||
context.footnote ("Start date modified.");
|
||||
|
@ -344,7 +344,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
|
|||
|
||||
if (task.get ("end") != "")
|
||||
{
|
||||
Date original (strtol (task.get ("end").c_str (), NULL, 10));
|
||||
Date original (task.get_date ("end"));
|
||||
if (!original.sameDay (edited))
|
||||
{
|
||||
context.footnote ("Done date modified.");
|
||||
|
@ -372,7 +372,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
|
|||
|
||||
if (task.get ("due") != "")
|
||||
{
|
||||
Date original (strtol (task.get ("due").c_str (), NULL, 10));
|
||||
Date original (task.get_date ("due"));
|
||||
if (!original.sameDay (edited))
|
||||
{
|
||||
context.footnote ("Due date modified.");
|
||||
|
@ -410,7 +410,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
|
|||
|
||||
if (task.get ("until") != "")
|
||||
{
|
||||
Date original (strtol (task.get ("until").c_str (), NULL, 10));
|
||||
Date original (task.get_date ("until"));
|
||||
if (!original.sameDay (edited))
|
||||
{
|
||||
context.footnote ("Until date modified.");
|
||||
|
@ -472,7 +472,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
|
|||
|
||||
if (task.get ("wait") != "")
|
||||
{
|
||||
Date original (strtol (task.get ("wait").c_str (), NULL, 10));
|
||||
Date original (task.get_date ("wait"));
|
||||
if (!original.sameDay (edited))
|
||||
{
|
||||
context.footnote ("Wait date modified.");
|
||||
|
|
|
@ -72,11 +72,11 @@ int CmdHistoryMonthly::execute (std::string& output)
|
|||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
{
|
||||
Date entry (task->get ("entry"));
|
||||
Date entry (task->get_date ("entry"));
|
||||
|
||||
Date end;
|
||||
if (task->has ("end"))
|
||||
end = Date (task->get ("end"));
|
||||
end = Date (task->get_date ("end"));
|
||||
|
||||
time_t epoch = entry.startOfMonth ().toEpoch ();
|
||||
groups[epoch] = 0;
|
||||
|
@ -232,11 +232,11 @@ int CmdHistoryAnnual::execute (std::string& output)
|
|||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
{
|
||||
Date entry (task->get ("entry"));
|
||||
Date entry (task->get_date ("entry"));
|
||||
|
||||
Date end;
|
||||
if (task->has ("end"))
|
||||
end = Date (task->get ("end"));
|
||||
end = Date (task->get_date ("end"));
|
||||
|
||||
time_t epoch = entry.startOfYear ().toEpoch ();
|
||||
groups[epoch] = 0;
|
||||
|
@ -389,11 +389,11 @@ int CmdGHistoryMonthly::execute (std::string& output)
|
|||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
{
|
||||
Date entry (task->get ("entry"));
|
||||
Date entry (task->get_date ("entry"));
|
||||
|
||||
Date end;
|
||||
if (task->has ("end"))
|
||||
end = Date (task->get ("end"));
|
||||
end = Date (task->get_date ("end"));
|
||||
|
||||
time_t epoch = entry.startOfMonth ().toEpoch ();
|
||||
groups[epoch] = 0;
|
||||
|
@ -588,11 +588,11 @@ int CmdGHistoryAnnual::execute (std::string& output)
|
|||
std::vector <Task>::iterator task;
|
||||
for (task = filtered.begin (); task != filtered.end (); ++task)
|
||||
{
|
||||
Date entry (task->get ("entry"));
|
||||
Date entry (task->get_date ("entry"));
|
||||
|
||||
Date end;
|
||||
if (task->has ("end"))
|
||||
end = Date (task->get ("end"));
|
||||
end = Date (task->get_date ("end"));
|
||||
|
||||
time_t epoch = entry.startOfYear ().toEpoch ();
|
||||
groups[epoch] = 0;
|
||||
|
|
|
@ -179,7 +179,7 @@ int CmdInfo::execute (std::string& output)
|
|||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_CMD_INFO_RECUR_UNTIL);
|
||||
|
||||
Date dt (strtol (task->get ("until").c_str (), NULL, 10));
|
||||
Date dt (task->get ("until"));
|
||||
std::string format = context.config.get ("reportdateformat");
|
||||
if (format == "")
|
||||
format = context.config.get ("dateformat");
|
||||
|
@ -227,7 +227,7 @@ int CmdInfo::execute (std::string& output)
|
|||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_WAITING);
|
||||
Date dt (strtol (task->get ("wait").c_str (), NULL, 10));
|
||||
Date dt (task->get_date ("wait"));
|
||||
view.set (row, 1, dt.toString (context.config.get ("dateformat")));
|
||||
}
|
||||
|
||||
|
@ -236,7 +236,7 @@ int CmdInfo::execute (std::string& output)
|
|||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_START);
|
||||
Date dt (strtol (task->get ("start").c_str (), NULL, 10));
|
||||
Date dt (task->get_date ("start"));
|
||||
view.set (row, 1, dt.toString (context.config.get ("dateformat")));
|
||||
}
|
||||
|
||||
|
@ -245,7 +245,7 @@ int CmdInfo::execute (std::string& output)
|
|||
{
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_END);
|
||||
Date dt (strtol (task->get ("end").c_str (), NULL, 10));
|
||||
Date dt (task->get_date ("end"));
|
||||
view.set (row, 1, dt.toString (context.config.get ("dateformat")));
|
||||
}
|
||||
|
||||
|
@ -271,7 +271,7 @@ int CmdInfo::execute (std::string& output)
|
|||
// entry
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, STRING_COLUMN_LABEL_ENTERED);
|
||||
Date dt (strtol (task->get ("entry").c_str (), NULL, 10));
|
||||
Date dt (task->get_date ("entry"));
|
||||
std::string entry = dt.toString (context.config.get ("dateformat"));
|
||||
|
||||
std::string age;
|
||||
|
|
|
@ -117,7 +117,7 @@ int CmdTimesheet::execute (std::string& output)
|
|||
// If task completed within range.
|
||||
if (task->getStatus () == Task::completed)
|
||||
{
|
||||
Date compDate (strtol (task->get ("end").c_str (), NULL, 10));
|
||||
Date compDate (task->get_date ("end"));
|
||||
if (compDate >= start && compDate < end)
|
||||
{
|
||||
Color c (task->get ("fg") + " " + task->get ("bg"));
|
||||
|
@ -155,7 +155,7 @@ int CmdTimesheet::execute (std::string& output)
|
|||
if (task->getStatus () == Task::pending &&
|
||||
task->has ("start"))
|
||||
{
|
||||
Date startDate (strtol (task->get ("start").c_str (), NULL, 10));
|
||||
Date startDate (task->get_date ("start"));
|
||||
if (startDate >= start && startDate < end)
|
||||
{
|
||||
Color c (task->get ("fg") + " " + task->get ("bg"));
|
||||
|
|
|
@ -107,8 +107,8 @@ void handleRecurrence ()
|
|||
|
||||
if (t->has ("wait"))
|
||||
{
|
||||
Date old_wait (atoi (t->get ("wait").c_str ()));
|
||||
Date old_due (atoi (t->get ("due").c_str ()));
|
||||
Date old_wait (t->get_date ("wait"));
|
||||
Date old_due (t->get_date ("due"));
|
||||
Date due (*d);
|
||||
sprintf (dueDate, "%u", (unsigned int) (due + (old_wait - old_due)).toEpoch ());
|
||||
rec.set ("wait", dueDate);
|
||||
|
@ -160,14 +160,14 @@ void handleRecurrence ()
|
|||
bool generateDueDates (Task& parent, std::vector <Date>& allDue)
|
||||
{
|
||||
// Determine due date, recur period and until date.
|
||||
Date due (atoi (parent.get ("due").c_str ()));
|
||||
Date due (parent.get_date ("due"));
|
||||
std::string recur = parent.get ("recur");
|
||||
|
||||
bool specificEnd = false;
|
||||
Date until;
|
||||
if (parent.get ("until") != "")
|
||||
{
|
||||
until = Date (atoi (parent.get ("until").c_str ()));
|
||||
until = Date (parent.get ("until"));
|
||||
specificEnd = true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue