From b670d4b072c599eaa59a8d2b24cda36b07eb5500 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 17 Dec 2016 22:18:46 -0500 Subject: [PATCH] Task: Migrated from ISO8601d to Datetime --- src/Task.cpp | 60 ++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/Task.cpp b/src/Task.cpp index 552bc2729..c0aaf4338 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -42,7 +42,7 @@ #include #endif #include -#include +#include #ifdef PRODUCT_TASKWARRIOR #include #endif @@ -321,9 +321,9 @@ Task::dateState Task::getDateState (const std::string& name) const std::string value = get (name); if (value.length ()) { - ISO8601d reference (value); - ISO8601d now; - ISO8601d today ("today"); + Datetime reference (value); + Datetime now; + Datetime today ("today"); if (reference < today) return dateBeforeToday; @@ -340,7 +340,7 @@ Task::dateState Task::getDateState (const std::string& name) const if (imminentperiod == 0) return dateAfterToday; - ISO8601d imminentDay = today + imminentperiod * 86400; + Datetime imminentDay = today + imminentperiod * 86400; if (reference < imminentDay) return dateAfterToday; } @@ -356,7 +356,7 @@ bool Task::is_ready () const return getStatus () == Task::pending && ! is_blocked && (! has ("scheduled") || - ISO8601d ("now").operator> (get_date ("scheduled"))); + Datetime ("now").operator> (get_date ("scheduled"))); } //////////////////////////////////////////////////////////////////////////////// @@ -390,7 +390,7 @@ bool Task::is_dueyesterday () const if (status != Task::completed && status != Task::deleted) { - if (ISO8601d ("yesterday").sameDay (get_date ("due"))) + if (Datetime ("yesterday").sameDay (get_date ("due"))) return true; } } @@ -428,7 +428,7 @@ bool Task::is_duetomorrow () const if (status != Task::completed && status != Task::deleted) { - if (ISO8601d ("tomorrow").sameDay (get_date ("due"))) + if (Datetime ("tomorrow").sameDay (get_date ("due"))) return true; } } @@ -446,8 +446,8 @@ bool Task::is_dueweek () const if (status != Task::completed && status != Task::deleted) { - ISO8601d due (get_date ("due")); - if (due.sameWeek (ISO8601d ())) + Datetime due (get_date ("due")); + if (due.sameWeek (Datetime ())) return true; } } @@ -465,8 +465,8 @@ bool Task::is_duemonth () const if (status != Task::completed && status != Task::deleted) { - ISO8601d due (get_date ("due")); - if (due.sameMonth (ISO8601d ())) + Datetime due (get_date ("due")); + if (due.sameMonth (Datetime ())) return true; } } @@ -484,8 +484,8 @@ bool Task::is_duequarter () const if (status != Task::completed && status != Task::deleted) { - ISO8601d due (get_date ("due")); - if (due.sameQuarter (ISO8601d ())) + Datetime due (get_date ("due")); + if (due.sameQuarter (Datetime ())) return true; } } @@ -503,8 +503,8 @@ bool Task::is_dueyear () const if (status != Task::completed && status != Task::deleted) { - ISO8601d due (get_date ("due")); - if (due.sameYear (ISO8601d ())) + Datetime due (get_date ("due")); + if (due.sameYear (Datetime ())) return true; } } @@ -665,7 +665,7 @@ void Task::parseJSON (const json::object* root_obj) { auto text = i.second->dump (); Lexer::dequote (text); - ISO8601d d (text); + Datetime d (text); set ("modified", d.toEpochString ()); } @@ -674,7 +674,7 @@ void Task::parseJSON (const json::object* root_obj) { auto text = i.second->dump (); Lexer::dequote (text); - ISO8601d d (text); + Datetime d (text); set (i.first, text == "" ? "" : d.toEpochString ()); } @@ -762,7 +762,7 @@ void Task::parseJSON (const json::object* root_obj) if (! what) throw format (STRING_TASK_NO_DESC, root_obj->dump ()); - std::string name = "annotation_" + ISO8601d (when->_data).toEpochString (); + std::string name = "annotation_" + Datetime (when->_data).toEpochString (); annos.insert (std::make_pair (name, json::decode (what->_data))); } @@ -893,7 +893,7 @@ std::string Task::composeJSON (bool decorate /*= false*/) const // Date fields are written as ISO 8601. if (type == "date") { - ISO8601d d (i.second); + Datetime d (i.second); out << '"' << (i.first == "modification" ? "modified" : i.first) << "\":\"" @@ -907,7 +907,7 @@ std::string Task::composeJSON (bool decorate /*= false*/) const /* else if (type == "duration") { - // TODO Emit ISO8601d + // TODO Emit Datetime } */ else if (type == "numeric") @@ -1006,7 +1006,7 @@ std::string Task::composeJSON (bool decorate /*= false*/) const if (annotations_written) out << ','; - ISO8601d d (i.first.substr (11)); + Datetime d (i.first.substr (11)); out << "{\"entry\":\"" << d.toISO () << "\",\"description\":\"" @@ -1547,9 +1547,9 @@ void Task::validate (bool applyDefault /* = true */) { Duration dur (Task::defaultDue); if (dur.toTime_t () != 0) - set ("due", (ISO8601d () + dur.toTime_t ()).toEpoch ()); + set ("due", (Datetime () + dur.toTime_t ()).toEpoch ()); else - set ("due", ISO8601d (Task::defaultDue).toEpoch ()); + set ("due", Datetime (Task::defaultDue).toEpoch ()); } } @@ -1628,8 +1628,8 @@ void Task::validate_before (const std::string& left, const std::string& right) if (has (left) && has (right)) { - ISO8601d date_left (get_date (left)); - ISO8601d date_right (get_date (right)); + Datetime date_left (get_date (left)); + Datetime date_right (get_date (right)); // if date is zero, then it is being removed (e.g. "due: wait:1day") if (date_left > date_right && date_right.toEpoch () != 0) @@ -1965,8 +1965,8 @@ float Task::urgency_due () const { if (has ("due")) { - ISO8601d now; - ISO8601d due (get_date ("due")); + Datetime now; + Datetime due (get_date ("due")); // Map a range of 21 days to the value 0.2 - 1.0 float days_overdue = (now - due) / 86400.0; @@ -1983,8 +1983,8 @@ float Task::urgency_age () const { assert (has ("entry")); - ISO8601d now; - ISO8601d entry (get_date ("entry")); + Datetime now; + Datetime entry (get_date ("entry")); int age = (now - entry) / 86400; // in days if (Task::urgencyAgeMax == 0 || age > Task::urgencyAgeMax)