diff --git a/src/Exclusion.cpp b/src/Exclusion.cpp index ff6c0e33..5560be49 100644 --- a/src/Exclusion.cpp +++ b/src/Exclusion.cpp @@ -56,13 +56,21 @@ void Exclusion::initialize (const std::string& line) { if (_tokens.size () == 4 && _tokens[1] == "day" && - (_tokens[2] == "on" || _tokens[2] == "off")) + _tokens[2] == "on") { + _additive = true; + return; + } + if (_tokens.size () == 4 && + _tokens[1] == "day" && + _tokens[2] == "off") + { + _additive = false; return; } else if (Datetime::dayOfWeek (_tokens[1]) != -1) - // TODO Check the time range args. { + _additive = false; return; } } @@ -76,6 +84,36 @@ std::vector Exclusion::tokens () const return _tokens; } +//////////////////////////////////////////////////////////////////////////////// +// Within range, yield a collection of recurring ranges as defined by _tokens. +// exc monday [ ...] +// exc day on +// exc day off +std::vector Exclusion::ranges (const Daterange& range) const +{ + std::vector results; + + if (_tokens[1] == "day" && + (_tokens[2] == "on" || + _tokens[2] == "off")) + { + Datetime start (_tokens[3]); + Datetime end (start); + ++end; + Daterange day (start, end); + if (range.overlap (day)) + results.push_back (day); + } + + return results; +} + +//////////////////////////////////////////////////////////////////////////////// +bool Exclusion::additive () const +{ + return _additive; +} + //////////////////////////////////////////////////////////////////////////////// std::string Exclusion::serialize () const { diff --git a/src/Exclusion.h b/src/Exclusion.h index 8b8d64c1..e0833692 100644 --- a/src/Exclusion.h +++ b/src/Exclusion.h @@ -28,6 +28,7 @@ #define INCLUDED_EXCLUSION #include +#include #include #include @@ -37,12 +38,15 @@ public: Exclusion () = default; void initialize (const std::string&); std::vector tokens () const; + std::vector ranges (const Daterange&) const; + bool additive () const; std::string serialize () const; std::string dump () const; private: - std::vector _tokens; + std::vector _tokens {}; + bool _additive {false}; }; #endif