diff --git a/src/ISO8601.cpp b/src/ISO8601.cpp index efcd3dde8..d9c09e626 100644 --- a/src/ISO8601.cpp +++ b/src/ISO8601.cpp @@ -1694,6 +1694,12 @@ bool ISO8601d::sameYear (const ISO8601d& rhs) const return this->year () == rhs.year (); } +//////////////////////////////////////////////////////////////////////////////// +ISO8601d ISO8601d::operator+ (time_t delta) +{ + return ISO8601d (_date + delta); +} + //////////////////////////////////////////////////////////////////////////////// ISO8601d ISO8601d::operator+ (const int delta) { diff --git a/src/ISO8601.h b/src/ISO8601.h index 32935866d..ff3e76413 100644 --- a/src/ISO8601.h +++ b/src/ISO8601.h @@ -95,6 +95,7 @@ public: bool sameWeek (const ISO8601d&) const; bool sameMonth (const ISO8601d&) const; bool sameYear (const ISO8601d&) const; + ISO8601d operator+ (time_t); ISO8601d operator+ (const int); ISO8601d operator- (const int); ISO8601d& operator+= (const int); diff --git a/src/commands/CmdEdit.cpp b/src/commands/CmdEdit.cpp index 2a4b71138..b685f4fc9 100644 --- a/src/commands/CmdEdit.cpp +++ b/src/commands/CmdEdit.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include diff --git a/src/commands/CmdHistory.cpp b/src/commands/CmdHistory.cpp index 4280d6387..6fa54344b 100644 --- a/src/commands/CmdHistory.cpp +++ b/src/commands/CmdHistory.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include diff --git a/src/commands/CmdStats.cpp b/src/commands/CmdStats.cpp index 4c630eefb..b819d84e3 100644 --- a/src/commands/CmdStats.cpp +++ b/src/commands/CmdStats.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include diff --git a/src/feedback.cpp b/src/feedback.cpp index 40b3fc594..56efbc66b 100644 --- a/src/feedback.cpp +++ b/src/feedback.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include diff --git a/src/main.h b/src/main.h index da73bc75b..fd8e8f714 100644 --- a/src/main.h +++ b/src/main.h @@ -32,13 +32,13 @@ #include #include #include -#include +#include #include // recur.cpp void handleRecurrence (); -Date getNextRecurrence (Date&, std::string&); -bool generateDueDates (Task&, std::vector &); +ISO8601d getNextRecurrence (ISO8601d&, std::string&); +bool generateDueDates (Task&, std::vector &); void updateRecurrenceMask (Task&); bool nag (Task&); diff --git a/src/recur.cpp b/src/recur.cpp index 6874542b4..cb038ddf0 100644 --- a/src/recur.cpp +++ b/src/recur.cpp @@ -39,8 +39,6 @@ #include #include -#include -#include #include #include #include @@ -62,7 +60,7 @@ void handleRecurrence () return; auto tasks = context.tdb2.pending.get_tasks (); - Date now; + ISO8601d now; // Look at all tasks and find any recurring ones. for (auto& t : tasks) @@ -71,7 +69,7 @@ void handleRecurrence () { // Generate a list of due dates for this recurring task, regardless of // the mask. - std::vector due; + std::vector due; if (!generateDueDates (t, due)) { // Determine the end date. @@ -106,9 +104,9 @@ void handleRecurrence () if (t.has ("wait")) { - Date old_wait (t.get_date ("wait")); - Date old_due (t.get_date ("due")); - Date due (d); + ISO8601d old_wait (t.get_date ("wait")); + ISO8601d old_due (t.get_date ("due")); + ISO8601d due (d); sprintf (dueDate, "%u", (unsigned int) (due + (old_wait - old_due)).toEpoch ()); rec.set ("wait", dueDate); rec.setStatus (Task::waiting); @@ -148,7 +146,7 @@ void handleRecurrence () else { if (t.has ("until") && - Date (t.get_date ("until")) < now) + ISO8601d (t.get_date ("until")) < now) { t.setStatus (Task::deleted); context.tdb2.modify(t); @@ -163,28 +161,28 @@ void handleRecurrence () // period (recur). Then generate a set of corresponding dates. // // Returns false if the parent recurring task is depleted. -bool generateDueDates (Task& parent, std::vector & allDue) +bool generateDueDates (Task& parent, std::vector & allDue) { // Determine due date, recur period and until date. - Date due (parent.get_date ("due")); - if (due == 0) + ISO8601d due (parent.get_date ("due")); + if (due._date == 0) { return false; } std::string recur = parent.get ("recur"); bool specificEnd = false; - Date until; + ISO8601d until; if (parent.get ("until") != "") { - until = Date (parent.get ("until")); + until = ISO8601d (parent.get ("until")); specificEnd = true; } int recurrence_limit = context.config.getInteger ("recurrence.limit"); int recurrence_counter = 0; - Date now; - for (Date i = due; ; i = getNextRecurrence (i, recur)) + ISO8601d now; + for (ISO8601d i = due; ; i = getNextRecurrence (i, recur)) { allDue.push_back (i); @@ -212,7 +210,7 @@ bool generateDueDates (Task& parent, std::vector & allDue) } //////////////////////////////////////////////////////////////////////////////// -Date getNextRecurrence (Date& current, std::string& period) +ISO8601d getNextRecurrence (ISO8601d& current, std::string& period) { int m = current.month (); int d = current.day (); @@ -228,10 +226,10 @@ Date getNextRecurrence (Date& current, std::string& period) ++y; } - while (! Date::valid (m, d, y)) + while (! ISO8601d::valid (m, d, y)) --d; - return Date (m, d, y); + return ISO8601d (m, d, y); } else if (period == "weekdays") @@ -258,10 +256,10 @@ Date getNextRecurrence (Date& current, std::string& period) ++y; } - while (! Date::valid (m, d, y)) + while (! ISO8601d::valid (m, d, y)) --d; - return Date (m, d, y); + return ISO8601d (m, d, y); } else if (period[0] == 'P' && @@ -277,10 +275,10 @@ Date getNextRecurrence (Date& current, std::string& period) ++y; } - while (! Date::valid (m, d, y)) + while (! ISO8601d::valid (m, d, y)) --d; - return Date (m, d, y); + return ISO8601d (m, d, y); } else if (period == "quarterly" || @@ -293,10 +291,10 @@ Date getNextRecurrence (Date& current, std::string& period) ++y; } - while (! Date::valid (m, d, y)) + while (! ISO8601d::valid (m, d, y)) --d; - return Date (m, d, y); + return ISO8601d (m, d, y); } else if (Lexer::isDigit (period[0]) && period[period.length () - 1] == 'q') @@ -310,10 +308,10 @@ Date getNextRecurrence (Date& current, std::string& period) ++y; } - while (! Date::valid (m, d, y)) + while (! ISO8601d::valid (m, d, y)) --d; - return Date (m, d, y); + return ISO8601d (m, d, y); } else if (period == "semiannual" || @@ -326,10 +324,10 @@ Date getNextRecurrence (Date& current, std::string& period) ++y; } - while (! Date::valid (m, d, y)) + while (! ISO8601d::valid (m, d, y)) --d; - return Date (m, d, y); + return ISO8601d (m, d, y); } else if (period == "bimonthly" || @@ -342,10 +340,10 @@ Date getNextRecurrence (Date& current, std::string& period) ++y; } - while (! Date::valid (m, d, y)) + while (! ISO8601d::valid (m, d, y)) --d; - return Date (m, d, y); + return ISO8601d (m, d, y); } else if (period == "biannual" || @@ -354,7 +352,7 @@ Date getNextRecurrence (Date& current, std::string& period) { y += 2; - return Date (m, d, y); + return ISO8601d (m, d, y); } else if (period == "annual" || @@ -368,7 +366,7 @@ Date getNextRecurrence (Date& current, std::string& period) if (m == 2 && d == 29) d = 28; - return Date (m, d, y); + return ISO8601d (m, d, y); } // Add the period to current, and we're done.