CmdEdit: Converted from ISO8601 to Datetime/Duration

This commit is contained in:
Paul Beckingham 2016-12-11 22:06:47 -05:00
parent 28bcb7e491
commit 1a4db03d5e

View file

@ -33,7 +33,8 @@
#include <algorithm> #include <algorithm>
#include <unistd.h> #include <unistd.h>
#include <cerrno> #include <cerrno>
#include <ISO8601.h> #include <Datetime.h>
#include <Duration.h>
#include <Context.h> #include <Context.h>
#include <Lexer.h> #include <Lexer.h>
#include <Filter.h> #include <Filter.h>
@ -174,10 +175,7 @@ std::string CmdEdit::formatDate (
{ {
std::string value = task.get (attribute); std::string value = task.get (attribute);
if (value.length ()) if (value.length ())
{ value = Datetime (value).toString (dateformat);
ISO8601d dt (value);
value = dt.toString (dateformat);
}
return value; return value;
} }
@ -189,10 +187,7 @@ std::string CmdEdit::formatDuration (
{ {
std::string value = task.get (attribute); std::string value = task.get (attribute);
if (value.length ()) if (value.length ())
{ value = Duration (value).formatISO ();
ISO8601p dur (value);
value = dur.format ();
}
return value; return value;
} }
@ -258,12 +253,12 @@ std::string CmdEdit::formatTask (Task task, const std::string& dateformat)
task.getAnnotations (annotations); task.getAnnotations (annotations);
for (auto& anno : annotations) for (auto& anno : annotations)
{ {
ISO8601d dt (strtol (anno.first.substr (11).c_str (), NULL, 10)); Datetime dt (strtol (anno.first.substr (11).c_str (), NULL, 10));
before << " Annotation: " << dt.toString (dateformat) before << " Annotation: " << dt.toString (dateformat)
<< " -- " << json::encode (anno.second) << '\n'; << " -- " << json::encode (anno.second) << '\n';
} }
ISO8601d now; Datetime now;
before << " Annotation: " << now.toString (dateformat) << " -- \n"; before << " Annotation: " << now.toString (dateformat) << " -- \n";
// Add dependencies here. // Add dependencies here.
@ -386,7 +381,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
if (formatted != value) if (formatted != value)
{ {
context.footnote (STRING_EDIT_ENTRY_MOD); context.footnote (STRING_EDIT_ENTRY_MOD);
task.set ("entry", ISO8601d (value, dateformat).toEpochString ()); task.set ("entry", Datetime (value, dateformat).toEpochString ());
} }
} }
else else
@ -403,13 +398,13 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
if (formatted != value) if (formatted != value)
{ {
context.footnote (STRING_EDIT_START_MOD); context.footnote (STRING_EDIT_START_MOD);
task.set ("start", ISO8601d (value, dateformat).toEpochString ()); task.set ("start", Datetime (value, dateformat).toEpochString ());
} }
} }
else else
{ {
context.footnote (STRING_EDIT_START_MOD); context.footnote (STRING_EDIT_START_MOD);
task.set ("start", ISO8601d (value, dateformat).toEpochString ()); task.set ("start", Datetime (value, dateformat).toEpochString ());
} }
} }
else else
@ -432,7 +427,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
if (formatted != value) if (formatted != value)
{ {
context.footnote (STRING_EDIT_END_MOD); context.footnote (STRING_EDIT_END_MOD);
task.set ("end", ISO8601d (value, dateformat).toEpochString ()); task.set ("end", Datetime (value, dateformat).toEpochString ());
} }
} }
else if (task.getStatus () != Task::deleted) else if (task.getStatus () != Task::deleted)
@ -459,13 +454,13 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
if (formatted != value) if (formatted != value)
{ {
context.footnote (STRING_EDIT_SCHED_MOD); context.footnote (STRING_EDIT_SCHED_MOD);
task.set ("scheduled", ISO8601d (value, dateformat).toEpochString ()); task.set ("scheduled", Datetime (value, dateformat).toEpochString ());
} }
} }
else else
{ {
context.footnote (STRING_EDIT_SCHED_MOD); context.footnote (STRING_EDIT_SCHED_MOD);
task.set ("scheduled", ISO8601d (value, dateformat).toEpochString ()); task.set ("scheduled", Datetime (value, dateformat).toEpochString ());
} }
} }
else else
@ -489,13 +484,13 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
if (formatted != value) if (formatted != value)
{ {
context.footnote (STRING_EDIT_DUE_MOD); context.footnote (STRING_EDIT_DUE_MOD);
task.set ("due", ISO8601d (value, dateformat).toEpochString ()); task.set ("due", Datetime (value, dateformat).toEpochString ());
} }
} }
else else
{ {
context.footnote (STRING_EDIT_DUE_MOD); context.footnote (STRING_EDIT_DUE_MOD);
task.set ("due", ISO8601d (value, dateformat).toEpochString ()); task.set ("due", Datetime (value, dateformat).toEpochString ());
} }
} }
else else
@ -526,13 +521,13 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
if (formatted != value) if (formatted != value)
{ {
context.footnote (STRING_EDIT_UNTIL_MOD); context.footnote (STRING_EDIT_UNTIL_MOD);
task.set ("until", ISO8601d (value, dateformat).toEpochString ()); task.set ("until", Datetime (value, dateformat).toEpochString ());
} }
} }
else else
{ {
context.footnote (STRING_EDIT_UNTIL_MOD); context.footnote (STRING_EDIT_UNTIL_MOD);
task.set ("until", ISO8601d (value, dateformat).toEpochString ()); task.set ("until", Datetime (value, dateformat).toEpochString ());
} }
} }
else else
@ -550,7 +545,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
{ {
if (value != "") if (value != "")
{ {
ISO8601p p; Duration p;
std::string::size_type idx = 0; std::string::size_type idx = 0;
if (p.parse (value, idx)) if (p.parse (value, idx))
{ {
@ -588,14 +583,14 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
if (formatted != value) if (formatted != value)
{ {
context.footnote (STRING_EDIT_WAIT_MOD); context.footnote (STRING_EDIT_WAIT_MOD);
task.set ("wait", ISO8601d (value, dateformat).toEpochString ()); task.set ("wait", Datetime (value, dateformat).toEpochString ());
task.setStatus (Task::waiting); task.setStatus (Task::waiting);
} }
} }
else else
{ {
context.footnote (STRING_EDIT_WAIT_MOD); context.footnote (STRING_EDIT_WAIT_MOD);
task.set ("wait", ISO8601d (value, dateformat).toEpochString ()); task.set ("wait", Datetime (value, dateformat).toEpochString ());
task.setStatus (Task::waiting); task.setStatus (Task::waiting);
} }
} }
@ -649,7 +644,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
// for each line: if the annotation is the same, then it is copied; if // for each line: if the annotation is the same, then it is copied; if
// the annotation is modified, then its original date may be kept; and // the annotation is modified, then its original date may be kept; and
// if there is no corresponding id, then a new unique date is created). // if there is no corresponding id, then a new unique date is created).
ISO8601d when (value.substr (0, gap), dateformat); Datetime when (value.substr (0, gap), dateformat);
// If the map already contains a annotation for a given timestamp // If the map already contains a annotation for a given timestamp
// we need to increment until we find an unused key // we need to increment until we find an unused key
@ -694,9 +689,9 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
{ {
std::string value = findValue (after, "\n UDA " + col.first + ":"); std::string value = findValue (after, "\n UDA " + col.first + ":");
if ((task.get (col.first) != value) && (type != "date" || if ((task.get (col.first) != value) && (type != "date" ||
(task.get (col.first) != ISO8601d (value, dateformat).toEpochString ())) && (task.get (col.first) != Datetime (value, dateformat).toEpochString ())) &&
(type != "duration" || (type != "duration" ||
(task.get (col.first) != (std::string) ISO8601p (value)))) (task.get (col.first) != Duration (value).toString ())))
{ {
if (value != "") if (value != "")
{ {
@ -718,11 +713,11 @@ void CmdEdit::parseTask (Task& task, const std::string& after, const std::string
} }
else if (type == "date") else if (type == "date")
{ {
task.set (col.first, ISO8601d (value, dateformat).toEpochString ()); task.set (col.first, Datetime (value, dateformat).toEpochString ());
} }
else if (type == "duration") else if (type == "duration")
{ {
task.set (col.first, (time_t) ISO8601p (value)); task.set (col.first, Duration (value).toTime_t ());
} }
} }
else else