mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Exclusion: Added range generation for 'day on' and 'day off'
This commit is contained in:
parent
71f442131c
commit
469bfdbf0a
2 changed files with 45 additions and 3 deletions
|
@ -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 <std::string> Exclusion::tokens () const
|
|||
return _tokens;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Within range, yield a collection of recurring ranges as defined by _tokens.
|
||||
// exc monday <block> [<block> ...]
|
||||
// exc day on <date>
|
||||
// exc day off <date>
|
||||
std::vector <Daterange> Exclusion::ranges (const Daterange& range) const
|
||||
{
|
||||
std::vector <Daterange> 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
|
||||
{
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#define INCLUDED_EXCLUSION
|
||||
|
||||
#include <Interval.h>
|
||||
#include <Daterange.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
|
@ -37,12 +38,15 @@ public:
|
|||
Exclusion () = default;
|
||||
void initialize (const std::string&);
|
||||
std::vector <std::string> tokens () const;
|
||||
std::vector <Daterange> ranges (const Daterange&) const;
|
||||
bool additive () const;
|
||||
|
||||
std::string serialize () const;
|
||||
std::string dump () const;
|
||||
|
||||
private:
|
||||
std::vector <std::string> _tokens;
|
||||
std::vector <std::string> _tokens {};
|
||||
bool _additive {false};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue