diff --git a/src/helper.cpp b/src/helper.cpp index 111afd54..d0a6cb74 100644 --- a/src/helper.cpp +++ b/src/helper.cpp @@ -173,3 +173,21 @@ Interval getLatestInterval ( } //////////////////////////////////////////////////////////////////////////////// +// An interval matches a filter if the start/end overlaps, and all filter tags +// are found in the interval. +bool intervalMatchesFilter (const Interval& interval, const Filter& filter) +{ + if (interval.end () > filter.start () && + interval.start () < filter.end ()) + { + for (auto& tag : filter.tags ()) + if (! interval.hasTag (tag)) + return false; + + return true; + } + + return false; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/timew.h b/src/timew.h index bd94c775..516dbfcf 100644 --- a/src/timew.h +++ b/src/timew.h @@ -50,6 +50,7 @@ void expandIntervalHint (const std::string&, std::string&, std::string&); Filter createFilterFromCLI (const CLI&); Timeline createTimelineFromData (const Rules&, Database&, const Filter&); Interval getLatestInterval (Timeline&, Database&, const Filter&); +bool intervalMatchesFilter (const Interval&, const Filter&); // utiƀ.cpp std::string osName ();