From 58d7de847815f818e40826b3ea3a7a9169abf307 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 28 Jun 2009 11:10:51 -0400 Subject: [PATCH] Enhancement - Implemented Task::validate. --- src/Task.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/src/Task.cpp b/src/Task.cpp index 52b95a3a8..592ef4649 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -28,6 +28,8 @@ #include #include #include "Nibbler.h" +#include "Date.h" +#include "Duration.h" #include "Task.h" #include "text.h" #include "util.h" @@ -519,17 +521,61 @@ void Task::removeTag (const std::string& tag) //////////////////////////////////////////////////////////////////////////////// void Task::validate () const { - // TODO Every task needs an ID. - - // TODO Every task needs an ID, entry and description attribute. - - - // TODO Verify until > due - // TODO Verify entry < until, due, start, end - // TODO If name == "recur", then Duration::valid (value). + // Every task needs an ID, entry and description attribute. + if (!has ("uuid") || + !has ("entry") || + !has ("description")) + throw std::string ("A task must have a uuid, entry date and description in order to be valid."); // TODO i18n if (get ("description") == "") // No i18n throw std::string ("Cannot add a task that is blank, or contains or characters."); // TODO i18n + + if (has ("due")) + { + Date due (::atoi (get ("due").c_str ())); + + // Verify until > due + if (has ("until")) + { + Date until (::atoi (get ("until").c_str ())); + if (due >= until) + throw std::string ("An 'until' date must be after a 'due' date."); // TODO i18n + } + + Date entry (::atoi (get ("entry").c_str ())); + + if (entry >= due) + throw std::string ("An 'entry' date must be before a 'due' date."); // TODO i18n + + if (has ("until")) + { + Date until (::atoi (get ("until").c_str ())); + if (entry >= until) + throw std::string ("An 'until' date must be after an 'entry' date."); // TODO i18n + } + + if (has ("start")) + { + Date start (::atoi (get ("start").c_str ())); + if (entry >= start) + throw std::string ("A 'start' date must be after an 'entry' date."); // TODO i18n + } + + if (has ("end")) + { + Date end (::atoi (get ("end").c_str ())); + if (entry >= end) + throw std::string ("An 'end' date must be after an 'entry' date."); // TODO i18n + } + } + + // Recur durations must be valid. + if (has ("recur")) + { + Duration d; + if (! d.valid (get ("recur"))) + throw std::string ("An 'end' date must be after an 'entry' date."); // TODO i18n + } } ////////////////////////////////////////////////////////////////////////////////