mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Range: Added ::combine for overlapping range combinations
This commit is contained in:
parent
9b4a70ea7b
commit
d5b7afd008
2 changed files with 38 additions and 0 deletions
|
@ -214,6 +214,43 @@ Range Range::intersect (const Range& other) const
|
|||
return Range (Datetime (0), Datetime (0));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// If the ranges do not overlap, the result is *this.
|
||||
//
|
||||
// this [----)
|
||||
// other [----)
|
||||
// result [-------)
|
||||
//
|
||||
// this [...
|
||||
// other [----)
|
||||
// result [...
|
||||
//
|
||||
// this [----)
|
||||
// other [...
|
||||
// result [...
|
||||
//
|
||||
// this [...
|
||||
// other [...
|
||||
// result [...
|
||||
//
|
||||
Range Range::combine (const Range& other) const
|
||||
{
|
||||
Range result {*this};
|
||||
|
||||
if (is_started () && other.is_started ())
|
||||
{
|
||||
// Start is hte earlier of the two.
|
||||
result.start = std::min (result.start, other.start);
|
||||
|
||||
if (is_open () || other.is_open ())
|
||||
result.end = {0};
|
||||
else
|
||||
result.end = std::max (result.end, other.end);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Consider the following overlap cases:
|
||||
//
|
||||
|
|
|
@ -48,6 +48,7 @@ public:
|
|||
bool overlap (const Range&) const;
|
||||
bool encloses (const Range&) const;
|
||||
Range intersect (const Range&) const;
|
||||
Range combine (const Range&) const;
|
||||
std::vector <Range> subtract (const Range&) const;
|
||||
time_t total () const;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue