mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Add endsWithin(Range...)
- use startsWithin/endsWithin in autoAdjust(...) - use Range::contains in startsWithin/endsWithin
This commit is contained in:
parent
592e2853e0
commit
bd65b67248
3 changed files with 18 additions and 5 deletions
|
@ -102,7 +102,8 @@ bool Range::is_empty () const
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool Range::contains (const Datetime &datetime) const
|
bool Range::contains (const Datetime &datetime) const
|
||||||
{
|
{
|
||||||
return start <= datetime && (! is_ended () || end >= datetime);
|
return (! is_started () || start <= datetime) &&
|
||||||
|
(! is_ended () || datetime < end);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -192,12 +193,23 @@ bool Range::startsWithin (const Range& other) const
|
||||||
return !other.is_started ();
|
return !other.is_started ();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (other.is_started () && start < other.start)
|
return other.contains (start);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool Range::endsWithin (const Range& other) const
|
||||||
|
{
|
||||||
|
if (other.is_empty ())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !other.is_ended () || start < other.end;
|
if (!is_ended ())
|
||||||
|
{
|
||||||
|
return !other.is_ended ();
|
||||||
|
}
|
||||||
|
|
||||||
|
return other.contains (end);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -52,6 +52,7 @@ public:
|
||||||
bool overlap (const Range&) const;
|
bool overlap (const Range&) const;
|
||||||
bool encloses (const Range&) const;
|
bool encloses (const Range&) const;
|
||||||
bool startsWithin (const Range &) const;
|
bool startsWithin (const Range &) const;
|
||||||
|
bool endsWithin (const Range &) const;
|
||||||
Range intersect (const Range&) const;
|
Range intersect (const Range&) const;
|
||||||
bool intersects (const Range&) const;
|
bool intersects (const Range&) const;
|
||||||
Range combine (const Range&) const;
|
Range combine (const Range&) const;
|
||||||
|
|
|
@ -116,8 +116,8 @@ static void autoAdjust (
|
||||||
// implement overwrite resolution, i.e. the new interval overwrites existing intervals
|
// implement overwrite resolution, i.e. the new interval overwrites existing intervals
|
||||||
for (auto& overlap : overlaps)
|
for (auto& overlap : overlaps)
|
||||||
{
|
{
|
||||||
bool start_within_overlap = overlap.range.contains (interval.range.start);
|
bool start_within_overlap = interval.range.startsWithin (overlap.range);
|
||||||
bool end_within_overlap = interval.range.end != 0 && overlap.range.contains (interval.range.end);
|
bool end_within_overlap = interval.range.endsWithin (overlap.range);
|
||||||
|
|
||||||
if (start_within_overlap && !end_within_overlap)
|
if (start_within_overlap && !end_within_overlap)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue