From d167842e36aa3b889eee417a0bc2018ed580b800 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 24 Jul 2011 23:34:15 -0400 Subject: [PATCH] Date - Implemented Date::get_relatives to retrieve a list of all the supported relative date constructs. --- src/Date.cpp | 80 ++++++++++++++++++++++++++++++++-------------------- src/Date.h | 2 ++ 2 files changed, 52 insertions(+), 30 deletions(-) diff --git a/src/Date.cpp b/src/Date.cpp index a50ac70fa..828c9e2d9 100644 --- a/src/Date.cpp +++ b/src/Date.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,42 @@ #include #include +static const char* relatives[] = +{ + "monday", + "tuesday", + "wednesday", + "thursday", + "friday", + "saturday", + "sunday", + "today", + "tomorrow", + "yesterday", + "eow", + "eoww", + "eocw", + "eom", + "eoy", + "sow", + "soww", + "socw", + "som", + "soy", + "goodfriday", + "easter", + "eastermonday", + "ascension", + "pentecost", + "midsommar", + "midsommarafton", + "now", + "later", + "someday", +}; + +#define NUM_RELATIVES (sizeof (relatives) / sizeof (relatives[0])) + extern Context context; //////////////////////////////////////////////////////////////////////////////// @@ -765,36 +802,8 @@ bool Date::isRelativeDate (const std::string& input) Date today; std::vector supported; - supported.push_back ("monday"); - supported.push_back ("tuesday"); - supported.push_back ("wednesday"); - supported.push_back ("thursday"); - supported.push_back ("friday"); - supported.push_back ("saturday"); - supported.push_back ("sunday"); - supported.push_back ("today"); - supported.push_back ("tomorrow"); - supported.push_back ("yesterday"); - supported.push_back ("eow"); - supported.push_back ("eoww"); - supported.push_back ("eocw"); - supported.push_back ("eom"); - supported.push_back ("eoy"); - supported.push_back ("sow"); - supported.push_back ("soww"); - supported.push_back ("socw"); - supported.push_back ("som"); - supported.push_back ("soy"); - supported.push_back ("goodfriday"); - supported.push_back ("easter"); - supported.push_back ("eastermonday"); - supported.push_back ("ascension"); - supported.push_back ("pentecost"); - supported.push_back ("midsommar"); - supported.push_back ("midsommarafton"); - supported.push_back ("now"); - supported.push_back ("later"); - supported.push_back ("someday"); + for (unsigned int i = 0; i < NUM_RELATIVES; ++i) + supported.push_back (relatives[i]); // Hard-coded 3, despite rc.abbreviation.minimum. std::vector matches; @@ -1022,3 +1031,14 @@ bool Date::isRelativeDate (const std::string& input) } //////////////////////////////////////////////////////////////////////////////// +const std::vector Date::get_relatives () +{ + std::vector all; + for (unsigned int i = 0; i < NUM_RELATIVES; ++i) + if (strcmp (relatives[i], "-")) + all.push_back (relatives[i]); + + return all; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Date.h b/src/Date.h index c15e251eb..c28c0733c 100644 --- a/src/Date.h +++ b/src/Date.h @@ -107,6 +107,8 @@ public: void operator++ (); // Prefix void operator++ (int); // Postfix + static const std::vector get_relatives (); + private: bool isEpoch (const std::string&); bool isRelativeDate (const std::string&);