Task: Migrated from Date to ISO8601d
This commit is contained in:
@@ -611,6 +611,7 @@ bool ISO8601d::parse_epoch (Nibbler& n)
|
|||||||
|
|
||||||
int epoch;
|
int epoch;
|
||||||
if (n.getUnsignedInt (epoch) &&
|
if (n.getUnsignedInt (epoch) &&
|
||||||
|
n.depleted () &&
|
||||||
epoch >= 315532800)
|
epoch >= 315532800)
|
||||||
{
|
{
|
||||||
_date = static_cast <time_t> (epoch);
|
_date = static_cast <time_t> (epoch);
|
||||||
|
|||||||
59
src/Task.cpp
59
src/Task.cpp
@@ -40,7 +40,6 @@
|
|||||||
#include <Lexer.h>
|
#include <Lexer.h>
|
||||||
#include <Nibbler.h>
|
#include <Nibbler.h>
|
||||||
#endif
|
#endif
|
||||||
#include <Date.h>
|
|
||||||
#include <ISO8601.h>
|
#include <ISO8601.h>
|
||||||
#include <Task.h>
|
#include <Task.h>
|
||||||
#ifdef PRODUCT_TASKWARRIOR
|
#ifdef PRODUCT_TASKWARRIOR
|
||||||
@@ -341,9 +340,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 ())
|
||||||
{
|
{
|
||||||
Date reference (value);
|
ISO8601d reference (value);
|
||||||
Date now;
|
ISO8601d now;
|
||||||
Date today ("today");
|
ISO8601d today ("today");
|
||||||
|
|
||||||
if (reference < today)
|
if (reference < today)
|
||||||
return dateBeforeToday;
|
return dateBeforeToday;
|
||||||
@@ -360,7 +359,7 @@ Task::dateState Task::getDateState (const std::string& name) const
|
|||||||
if (imminentperiod == 0)
|
if (imminentperiod == 0)
|
||||||
return dateAfterToday;
|
return dateAfterToday;
|
||||||
|
|
||||||
Date imminentDay = today + imminentperiod * 86400;
|
ISO8601d imminentDay = today + imminentperiod * 86400;
|
||||||
if (reference < imminentDay)
|
if (reference < imminentDay)
|
||||||
return dateAfterToday;
|
return dateAfterToday;
|
||||||
}
|
}
|
||||||
@@ -377,7 +376,7 @@ bool Task::is_ready () const
|
|||||||
return getStatus () == Task::pending &&
|
return getStatus () == Task::pending &&
|
||||||
! is_blocked &&
|
! is_blocked &&
|
||||||
(! has ("scheduled") ||
|
(! has ("scheduled") ||
|
||||||
Date ("now").operator> (get_date ("scheduled")));
|
ISO8601d ("now").operator> (get_date ("scheduled")));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -411,7 +410,7 @@ bool Task::is_dueyesterday () const
|
|||||||
if (status != Task::completed &&
|
if (status != Task::completed &&
|
||||||
status != Task::deleted)
|
status != Task::deleted)
|
||||||
{
|
{
|
||||||
if (Date ("yesterday").sameDay (get_date ("due")))
|
if (ISO8601d ("yesterday").sameDay (get_date ("due")))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -449,7 +448,7 @@ bool Task::is_duetomorrow () const
|
|||||||
if (status != Task::completed &&
|
if (status != Task::completed &&
|
||||||
status != Task::deleted)
|
status != Task::deleted)
|
||||||
{
|
{
|
||||||
if (Date ("tomorrow").sameDay (get_date ("due")))
|
if (ISO8601d ("tomorrow").sameDay (get_date ("due")))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -467,9 +466,9 @@ bool Task::is_dueweek () const
|
|||||||
if (status != Task::completed &&
|
if (status != Task::completed &&
|
||||||
status != Task::deleted)
|
status != Task::deleted)
|
||||||
{
|
{
|
||||||
Date due (get_date ("due"));
|
ISO8601d due (get_date ("due"));
|
||||||
if (due >= Date ("socw") &&
|
if (due >= ISO8601d ("socw") &&
|
||||||
due <= Date ("eocw"))
|
due <= ISO8601d ("eocw"))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -487,9 +486,9 @@ bool Task::is_duemonth () const
|
|||||||
if (status != Task::completed &&
|
if (status != Task::completed &&
|
||||||
status != Task::deleted)
|
status != Task::deleted)
|
||||||
{
|
{
|
||||||
Date due (get_date ("due"));
|
ISO8601d due (get_date ("due"));
|
||||||
if (due >= Date ("socm") &&
|
if (due >= ISO8601d ("socm") &&
|
||||||
due <= Date ("eocm"))
|
due <= ISO8601d ("eocm"))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -507,8 +506,8 @@ bool Task::is_dueyear () const
|
|||||||
if (status != Task::completed &&
|
if (status != Task::completed &&
|
||||||
status != Task::deleted)
|
status != Task::deleted)
|
||||||
{
|
{
|
||||||
Date now;
|
ISO8601d now;
|
||||||
Date due (get_date ("due"));
|
ISO8601d due (get_date ("due"));
|
||||||
if (now.year () == due.year ())
|
if (now.year () == due.year ())
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -674,7 +673,7 @@ void Task::parseJSON (const json::object* root_obj)
|
|||||||
// TW-1274 Standardization.
|
// TW-1274 Standardization.
|
||||||
else if (i.first == "modification")
|
else if (i.first == "modification")
|
||||||
{
|
{
|
||||||
Date d (unquoteText (i.second->dump ()));
|
ISO8601d d (unquoteText (i.second->dump ()));
|
||||||
set ("modified", d.toEpochString ());
|
set ("modified", d.toEpochString ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -682,7 +681,7 @@ void Task::parseJSON (const json::object* root_obj)
|
|||||||
else if (type == "date")
|
else if (type == "date")
|
||||||
{
|
{
|
||||||
std::string text = unquoteText (i.second->dump ());
|
std::string text = unquoteText (i.second->dump ());
|
||||||
Date d (text);
|
ISO8601d d (text);
|
||||||
set (i.first, text == "" ? "" : d.toEpochString ());
|
set (i.first, text == "" ? "" : d.toEpochString ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -747,7 +746,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_" + Date (when->_data).toEpochString ();
|
std::string name = "annotation_" + ISO8601d (when->_data).toEpochString ();
|
||||||
annos.insert (std::make_pair (name, json::decode (what->_data)));
|
annos.insert (std::make_pair (name, json::decode (what->_data)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -865,7 +864,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")
|
||||||
{
|
{
|
||||||
Date d (i.second);
|
ISO8601d d (i.second);
|
||||||
out << "\""
|
out << "\""
|
||||||
<< (i.first == "modification" ? "modified" : i.first)
|
<< (i.first == "modification" ? "modified" : i.first)
|
||||||
<< "\":\""
|
<< "\":\""
|
||||||
@@ -960,7 +959,7 @@ std::string Task::composeJSON (bool decorate /*= false*/) const
|
|||||||
if (annotations_written)
|
if (annotations_written)
|
||||||
out << ",";
|
out << ",";
|
||||||
|
|
||||||
Date d (i.first.substr (11));
|
ISO8601d d (i.first.substr (11));
|
||||||
out << "{\"entry\":\""
|
out << "{\"entry\":\""
|
||||||
<< d.toISO ()
|
<< d.toISO ()
|
||||||
<< "\",\"description\":\""
|
<< "\",\"description\":\""
|
||||||
@@ -1487,9 +1486,9 @@ void Task::validate (bool applyDefault /* = true */)
|
|||||||
{
|
{
|
||||||
ISO8601p dur (Task::defaultDue);
|
ISO8601p dur (Task::defaultDue);
|
||||||
if ((time_t) dur != 0)
|
if ((time_t) dur != 0)
|
||||||
set ("due", (Date () + dur).toEpoch ());
|
set ("due", (ISO8601d () + dur).toEpoch ());
|
||||||
else
|
else
|
||||||
set ("due", Date (Task::defaultDue).toEpoch ());
|
set ("due", ISO8601d (Task::defaultDue).toEpoch ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1568,11 +1567,11 @@ void Task::validate_before (const std::string& left, const std::string& right)
|
|||||||
if (has (left) &&
|
if (has (left) &&
|
||||||
has (right))
|
has (right))
|
||||||
{
|
{
|
||||||
Date date_left (get_date (left));
|
ISO8601d date_left (get_date (left));
|
||||||
Date date_right (get_date (right));
|
ISO8601d 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 != 0)
|
if (date_left > date_right && date_right.toEpoch () != 0)
|
||||||
context.footnote (format (STRING_TASK_VALID_BEFORE, left, right));
|
context.footnote (format (STRING_TASK_VALID_BEFORE, left, right));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -1923,8 +1922,8 @@ float Task::urgency_due () const
|
|||||||
{
|
{
|
||||||
if (has ("due"))
|
if (has ("due"))
|
||||||
{
|
{
|
||||||
Date now;
|
ISO8601d now;
|
||||||
Date due (get_date ("due"));
|
ISO8601d 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;
|
||||||
@@ -1941,8 +1940,8 @@ float Task::urgency_age () const
|
|||||||
{
|
{
|
||||||
assert (has ("entry"));
|
assert (has ("entry"));
|
||||||
|
|
||||||
Date now;
|
ISO8601d now;
|
||||||
Date entry (get_date ("entry"));
|
ISO8601d 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)
|
||||||
|
|||||||
@@ -33,7 +33,6 @@
|
|||||||
#include <Variant.h>
|
#include <Variant.h>
|
||||||
#include <ISO8601.h>
|
#include <ISO8601.h>
|
||||||
#include <Lexer.h>
|
#include <Lexer.h>
|
||||||
#include <Date.h>
|
|
||||||
#include <RX.h>
|
#include <RX.h>
|
||||||
#include <text.h>
|
#include <text.h>
|
||||||
#include <i18n.h>
|
#include <i18n.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user