Recur: Migrated recurrence from Date to ISO8601d

- Changed signature of recur functions, which needed a main.h change, which led
  to removing '#include <Date.h>' from main.h, which necessitated adding the
  sam include to various other source files.  Temporarily.
- Added 'ISO8601d ISO8601d::operator+ (time_t)', because of differences from the
  original Date object.
This commit is contained in:
Paul Beckingham 2015-09-30 09:52:09 -04:00
parent 953e1e4cc1
commit 4f156c407c
8 changed files with 44 additions and 35 deletions

View file

@ -1694,6 +1694,12 @@ bool ISO8601d::sameYear (const ISO8601d& rhs) const
return this->year () == rhs.year (); return this->year () == rhs.year ();
} }
////////////////////////////////////////////////////////////////////////////////
ISO8601d ISO8601d::operator+ (time_t delta)
{
return ISO8601d (_date + delta);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ISO8601d ISO8601d::operator+ (const int delta) ISO8601d ISO8601d::operator+ (const int delta)
{ {

View file

@ -95,6 +95,7 @@ public:
bool sameWeek (const ISO8601d&) const; bool sameWeek (const ISO8601d&) const;
bool sameMonth (const ISO8601d&) const; bool sameMonth (const ISO8601d&) const;
bool sameYear (const ISO8601d&) const; bool sameYear (const ISO8601d&) const;
ISO8601d operator+ (time_t);
ISO8601d operator+ (const int); ISO8601d operator+ (const int);
ISO8601d operator- (const int); ISO8601d operator- (const int);
ISO8601d& operator+= (const int); ISO8601d& operator+= (const int);

View file

@ -31,6 +31,7 @@
#include <cstring> #include <cstring>
#include <algorithm> #include <algorithm>
#include <unistd.h> #include <unistd.h>
#include <Date.h>
#include <ISO8601.h> #include <ISO8601.h>
#include <Context.h> #include <Context.h>
#include <Filter.h> #include <Filter.h>

View file

@ -32,6 +32,7 @@
#include <main.h> #include <main.h>
#include <text.h> #include <text.h>
#include <i18n.h> #include <i18n.h>
#include <Date.h>
#include <ISO8601.h> #include <ISO8601.h>
#include <CmdHistory.h> #include <CmdHistory.h>

View file

@ -29,6 +29,7 @@
#include <iomanip> #include <iomanip>
#include <stdlib.h> #include <stdlib.h>
#include <ViewText.h> #include <ViewText.h>
#include <Date.h>
#include <ISO8601.h> #include <ISO8601.h>
#include <Context.h> #include <Context.h>
#include <Filter.h> #include <Filter.h>

View file

@ -33,6 +33,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <inttypes.h> #include <inttypes.h>
#include <Context.h> #include <Context.h>
#include <Date.h>
#include <ISO8601.h> #include <ISO8601.h>
#include <main.h> #include <main.h>
#include <text.h> #include <text.h>

View file

@ -32,13 +32,13 @@
#include <map> #include <map>
#include <sys/types.h> #include <sys/types.h>
#include <Context.h> #include <Context.h>
#include <Date.h> #include <ISO8601.h>
#include <Color.h> #include <Color.h>
// recur.cpp // recur.cpp
void handleRecurrence (); void handleRecurrence ();
Date getNextRecurrence (Date&, std::string&); ISO8601d getNextRecurrence (ISO8601d&, std::string&);
bool generateDueDates (Task&, std::vector <Date>&); bool generateDueDates (Task&, std::vector <ISO8601d>&);
void updateRecurrenceMask (Task&); void updateRecurrenceMask (Task&);
bool nag (Task&); bool nag (Task&);

View file

@ -39,8 +39,6 @@
#include <time.h> #include <time.h>
#include <Context.h> #include <Context.h>
#include <Date.h>
#include <ISO8601.h>
#include <Lexer.h> #include <Lexer.h>
#include <ISO8601.h> #include <ISO8601.h>
#include <text.h> #include <text.h>
@ -62,7 +60,7 @@ void handleRecurrence ()
return; return;
auto tasks = context.tdb2.pending.get_tasks (); auto tasks = context.tdb2.pending.get_tasks ();
Date now; ISO8601d now;
// Look at all tasks and find any recurring ones. // Look at all tasks and find any recurring ones.
for (auto& t : tasks) for (auto& t : tasks)
@ -71,7 +69,7 @@ void handleRecurrence ()
{ {
// Generate a list of due dates for this recurring task, regardless of // Generate a list of due dates for this recurring task, regardless of
// the mask. // the mask.
std::vector <Date> due; std::vector <ISO8601d> due;
if (!generateDueDates (t, due)) if (!generateDueDates (t, due))
{ {
// Determine the end date. // Determine the end date.
@ -106,9 +104,9 @@ void handleRecurrence ()
if (t.has ("wait")) if (t.has ("wait"))
{ {
Date old_wait (t.get_date ("wait")); ISO8601d old_wait (t.get_date ("wait"));
Date old_due (t.get_date ("due")); ISO8601d old_due (t.get_date ("due"));
Date due (d); ISO8601d due (d);
sprintf (dueDate, "%u", (unsigned int) (due + (old_wait - old_due)).toEpoch ()); sprintf (dueDate, "%u", (unsigned int) (due + (old_wait - old_due)).toEpoch ());
rec.set ("wait", dueDate); rec.set ("wait", dueDate);
rec.setStatus (Task::waiting); rec.setStatus (Task::waiting);
@ -148,7 +146,7 @@ void handleRecurrence ()
else else
{ {
if (t.has ("until") && if (t.has ("until") &&
Date (t.get_date ("until")) < now) ISO8601d (t.get_date ("until")) < now)
{ {
t.setStatus (Task::deleted); t.setStatus (Task::deleted);
context.tdb2.modify(t); context.tdb2.modify(t);
@ -163,28 +161,28 @@ void handleRecurrence ()
// period (recur). Then generate a set of corresponding dates. // period (recur). Then generate a set of corresponding dates.
// //
// Returns false if the parent recurring task is depleted. // Returns false if the parent recurring task is depleted.
bool generateDueDates (Task& parent, std::vector <Date>& allDue) bool generateDueDates (Task& parent, std::vector <ISO8601d>& allDue)
{ {
// Determine due date, recur period and until date. // Determine due date, recur period and until date.
Date due (parent.get_date ("due")); ISO8601d due (parent.get_date ("due"));
if (due == 0) if (due._date == 0)
{ {
return false; return false;
} }
std::string recur = parent.get ("recur"); std::string recur = parent.get ("recur");
bool specificEnd = false; bool specificEnd = false;
Date until; ISO8601d until;
if (parent.get ("until") != "") if (parent.get ("until") != "")
{ {
until = Date (parent.get ("until")); until = ISO8601d (parent.get ("until"));
specificEnd = true; specificEnd = true;
} }
int recurrence_limit = context.config.getInteger ("recurrence.limit"); int recurrence_limit = context.config.getInteger ("recurrence.limit");
int recurrence_counter = 0; int recurrence_counter = 0;
Date now; ISO8601d now;
for (Date i = due; ; i = getNextRecurrence (i, recur)) for (ISO8601d i = due; ; i = getNextRecurrence (i, recur))
{ {
allDue.push_back (i); allDue.push_back (i);
@ -212,7 +210,7 @@ bool generateDueDates (Task& parent, std::vector <Date>& allDue)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Date getNextRecurrence (Date& current, std::string& period) ISO8601d getNextRecurrence (ISO8601d& current, std::string& period)
{ {
int m = current.month (); int m = current.month ();
int d = current.day (); int d = current.day ();
@ -228,10 +226,10 @@ Date getNextRecurrence (Date& current, std::string& period)
++y; ++y;
} }
while (! Date::valid (m, d, y)) while (! ISO8601d::valid (m, d, y))
--d; --d;
return Date (m, d, y); return ISO8601d (m, d, y);
} }
else if (period == "weekdays") else if (period == "weekdays")
@ -258,10 +256,10 @@ Date getNextRecurrence (Date& current, std::string& period)
++y; ++y;
} }
while (! Date::valid (m, d, y)) while (! ISO8601d::valid (m, d, y))
--d; --d;
return Date (m, d, y); return ISO8601d (m, d, y);
} }
else if (period[0] == 'P' && else if (period[0] == 'P' &&
@ -277,10 +275,10 @@ Date getNextRecurrence (Date& current, std::string& period)
++y; ++y;
} }
while (! Date::valid (m, d, y)) while (! ISO8601d::valid (m, d, y))
--d; --d;
return Date (m, d, y); return ISO8601d (m, d, y);
} }
else if (period == "quarterly" || else if (period == "quarterly" ||
@ -293,10 +291,10 @@ Date getNextRecurrence (Date& current, std::string& period)
++y; ++y;
} }
while (! Date::valid (m, d, y)) while (! ISO8601d::valid (m, d, y))
--d; --d;
return Date (m, d, y); return ISO8601d (m, d, y);
} }
else if (Lexer::isDigit (period[0]) && period[period.length () - 1] == 'q') else if (Lexer::isDigit (period[0]) && period[period.length () - 1] == 'q')
@ -310,10 +308,10 @@ Date getNextRecurrence (Date& current, std::string& period)
++y; ++y;
} }
while (! Date::valid (m, d, y)) while (! ISO8601d::valid (m, d, y))
--d; --d;
return Date (m, d, y); return ISO8601d (m, d, y);
} }
else if (period == "semiannual" || else if (period == "semiannual" ||
@ -326,10 +324,10 @@ Date getNextRecurrence (Date& current, std::string& period)
++y; ++y;
} }
while (! Date::valid (m, d, y)) while (! ISO8601d::valid (m, d, y))
--d; --d;
return Date (m, d, y); return ISO8601d (m, d, y);
} }
else if (period == "bimonthly" || else if (period == "bimonthly" ||
@ -342,10 +340,10 @@ Date getNextRecurrence (Date& current, std::string& period)
++y; ++y;
} }
while (! Date::valid (m, d, y)) while (! ISO8601d::valid (m, d, y))
--d; --d;
return Date (m, d, y); return ISO8601d (m, d, y);
} }
else if (period == "biannual" || else if (period == "biannual" ||
@ -354,7 +352,7 @@ Date getNextRecurrence (Date& current, std::string& period)
{ {
y += 2; y += 2;
return Date (m, d, y); return ISO8601d (m, d, y);
} }
else if (period == "annual" || else if (period == "annual" ||
@ -368,7 +366,7 @@ Date getNextRecurrence (Date& current, std::string& period)
if (m == 2 && d == 29) if (m == 2 && d == 29)
d = 28; d = 28;
return Date (m, d, y); return ISO8601d (m, d, y);
} }
// Add the period to current, and we're done. // Add the period to current, and we're done.