Task: Migrated from ISO8601d to Datetime

This commit is contained in:
Paul Beckingham 2016-12-17 22:18:46 -05:00
parent d8d5b14e66
commit 73e373527f

View file

@ -42,7 +42,7 @@
#include <Pig.h> #include <Pig.h>
#endif #endif
#include <Duration.h> #include <Duration.h>
#include <ISO8601.h> #include <Datetime.h>
#ifdef PRODUCT_TASKWARRIOR #ifdef PRODUCT_TASKWARRIOR
#include <RX.h> #include <RX.h>
#endif #endif
@ -321,9 +321,9 @@ Task::dateState Task::getDateState (const std::string& name) const
std::string value = get (name); std::string value = get (name);
if (value.length ()) if (value.length ())
{ {
ISO8601d reference (value); Datetime reference (value);
ISO8601d now; Datetime now;
ISO8601d today ("today"); Datetime today ("today");
if (reference < today) if (reference < today)
return dateBeforeToday; return dateBeforeToday;
@ -340,7 +340,7 @@ Task::dateState Task::getDateState (const std::string& name) const
if (imminentperiod == 0) if (imminentperiod == 0)
return dateAfterToday; return dateAfterToday;
ISO8601d imminentDay = today + imminentperiod * 86400; Datetime imminentDay = today + imminentperiod * 86400;
if (reference < imminentDay) if (reference < imminentDay)
return dateAfterToday; return dateAfterToday;
} }
@ -356,7 +356,7 @@ bool Task::is_ready () const
return getStatus () == Task::pending && return getStatus () == Task::pending &&
! is_blocked && ! is_blocked &&
(! has ("scheduled") || (! 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 && if (status != Task::completed &&
status != Task::deleted) status != Task::deleted)
{ {
if (ISO8601d ("yesterday").sameDay (get_date ("due"))) if (Datetime ("yesterday").sameDay (get_date ("due")))
return true; return true;
} }
} }
@ -428,7 +428,7 @@ bool Task::is_duetomorrow () const
if (status != Task::completed && if (status != Task::completed &&
status != Task::deleted) status != Task::deleted)
{ {
if (ISO8601d ("tomorrow").sameDay (get_date ("due"))) if (Datetime ("tomorrow").sameDay (get_date ("due")))
return true; return true;
} }
} }
@ -446,8 +446,8 @@ bool Task::is_dueweek () const
if (status != Task::completed && if (status != Task::completed &&
status != Task::deleted) status != Task::deleted)
{ {
ISO8601d due (get_date ("due")); Datetime due (get_date ("due"));
if (due.sameWeek (ISO8601d ())) if (due.sameWeek (Datetime ()))
return true; return true;
} }
} }
@ -465,8 +465,8 @@ bool Task::is_duemonth () const
if (status != Task::completed && if (status != Task::completed &&
status != Task::deleted) status != Task::deleted)
{ {
ISO8601d due (get_date ("due")); Datetime due (get_date ("due"));
if (due.sameMonth (ISO8601d ())) if (due.sameMonth (Datetime ()))
return true; return true;
} }
} }
@ -484,8 +484,8 @@ bool Task::is_duequarter () const
if (status != Task::completed && if (status != Task::completed &&
status != Task::deleted) status != Task::deleted)
{ {
ISO8601d due (get_date ("due")); Datetime due (get_date ("due"));
if (due.sameQuarter (ISO8601d ())) if (due.sameQuarter (Datetime ()))
return true; return true;
} }
} }
@ -503,8 +503,8 @@ bool Task::is_dueyear () const
if (status != Task::completed && if (status != Task::completed &&
status != Task::deleted) status != Task::deleted)
{ {
ISO8601d due (get_date ("due")); Datetime due (get_date ("due"));
if (due.sameYear (ISO8601d ())) if (due.sameYear (Datetime ()))
return true; return true;
} }
} }
@ -665,7 +665,7 @@ void Task::parseJSON (const json::object* root_obj)
{ {
auto text = i.second->dump (); auto text = i.second->dump ();
Lexer::dequote (text); Lexer::dequote (text);
ISO8601d d (text); Datetime d (text);
set ("modified", d.toEpochString ()); set ("modified", d.toEpochString ());
} }
@ -674,7 +674,7 @@ void Task::parseJSON (const json::object* root_obj)
{ {
auto text = i.second->dump (); auto text = i.second->dump ();
Lexer::dequote (text); Lexer::dequote (text);
ISO8601d d (text); Datetime d (text);
set (i.first, text == "" ? "" : d.toEpochString ()); set (i.first, text == "" ? "" : d.toEpochString ());
} }
@ -762,7 +762,7 @@ void Task::parseJSON (const json::object* root_obj)
if (! what) if (! what)
throw format (STRING_TASK_NO_DESC, root_obj->dump ()); 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))); 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. // Date fields are written as ISO 8601.
if (type == "date") if (type == "date")
{ {
ISO8601d d (i.second); Datetime d (i.second);
out << '"' out << '"'
<< (i.first == "modification" ? "modified" : i.first) << (i.first == "modification" ? "modified" : i.first)
<< "\":\"" << "\":\""
@ -907,7 +907,7 @@ std::string Task::composeJSON (bool decorate /*= false*/) const
/* /*
else if (type == "duration") else if (type == "duration")
{ {
// TODO Emit ISO8601d // TODO Emit Datetime
} }
*/ */
else if (type == "numeric") else if (type == "numeric")
@ -1006,7 +1006,7 @@ std::string Task::composeJSON (bool decorate /*= false*/) const
if (annotations_written) if (annotations_written)
out << ','; out << ',';
ISO8601d d (i.first.substr (11)); Datetime d (i.first.substr (11));
out << "{\"entry\":\"" out << "{\"entry\":\""
<< d.toISO () << d.toISO ()
<< "\",\"description\":\"" << "\",\"description\":\""
@ -1547,9 +1547,9 @@ void Task::validate (bool applyDefault /* = true */)
{ {
Duration dur (Task::defaultDue); Duration dur (Task::defaultDue);
if (dur.toTime_t () != 0) if (dur.toTime_t () != 0)
set ("due", (ISO8601d () + dur.toTime_t ()).toEpoch ()); set ("due", (Datetime () + dur.toTime_t ()).toEpoch ());
else 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) && if (has (left) &&
has (right)) has (right))
{ {
ISO8601d date_left (get_date (left)); Datetime date_left (get_date (left));
ISO8601d date_right (get_date (right)); Datetime date_right (get_date (right));
// if date is zero, then it is being removed (e.g. "due: wait:1day") // if date is zero, then it is being removed (e.g. "due: wait:1day")
if (date_left > date_right && date_right.toEpoch () != 0) if (date_left > date_right && date_right.toEpoch () != 0)
@ -1965,8 +1965,8 @@ float Task::urgency_due () const
{ {
if (has ("due")) if (has ("due"))
{ {
ISO8601d now; Datetime now;
ISO8601d due (get_date ("due")); Datetime due (get_date ("due"));
// Map a range of 21 days to the value 0.2 - 1.0 // Map a range of 21 days to the value 0.2 - 1.0
float days_overdue = (now - due) / 86400.0; float days_overdue = (now - due) / 86400.0;
@ -1983,8 +1983,8 @@ float Task::urgency_age () const
{ {
assert (has ("entry")); assert (has ("entry"));
ISO8601d now; Datetime now;
ISO8601d entry (get_date ("entry")); Datetime entry (get_date ("entry"));
int age = (now - entry) / 86400; // in days int age = (now - entry) / 86400; // in days
if (Task::urgencyAgeMax == 0 || age > Task::urgencyAgeMax) if (Task::urgencyAgeMax == 0 || age > Task::urgencyAgeMax)