Adapt standard overlap resolution

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
This commit is contained in:
Thomas Lauf 2020-07-08 21:48:31 +02:00
parent 4aacba47df
commit 1c1066ae6c

View file

@ -97,6 +97,8 @@ static void autoAdjust (
Database& database, Database& database,
Interval& interval) Interval& interval)
{ {
const bool verbose = rules.getBoolean ("verbose");
Interval overlaps_filter {interval.start, interval.end}; Interval overlaps_filter {interval.start, interval.end};
auto overlaps = getTracked (database, rules, overlaps_filter); auto overlaps = getTracked (database, rules, overlaps_filter);
@ -113,33 +115,9 @@ static void autoAdjust (
debug (" " + overlap.dump ()); debug (" " + overlap.dump ());
} }
auto verbose = rules.getBoolean ("verbose");
if (! adjust) if (! adjust)
{ {
// standard overlap resolution: an open interval can truncate another open interval throw std::string ("You cannot overlap intervals. Correct the start/end time, or specify the :adjust hint.");
if (overlaps.size () == 1)
{
auto overlap = overlaps[0];
if (overlap.is_open () && interval.is_open () && interval.startsWithin (overlap))
{
// start date of new interval within old interval
Interval modified {overlap};
modified.end = interval.start;
database.modifyInterval (overlap, modified, verbose);
if (verbose)
{
std::cout << '\n' << intervalSummarize (database, rules, modified);
}
return;
}
}
throw std::string("You cannot overlap intervals. Correct the start/end "
"time, or specify the :adjust hint.");
} }
else else
{ {