TI-58: Fix bug 'Delete command is not always deleting'

- Update database before deleting sythetic intervals
- Make Exclusion::ranges work with open interval
This commit is contained in:
Thomas Lauf 2017-04-05 22:53:53 +02:00
parent 98218c4b75
commit ad67539f94
4 changed files with 35 additions and 3 deletions

View file

@ -120,7 +120,15 @@ std::vector <Range> Exclusion::ranges (const Range& range) const
else if ((dayOfWeek = Datetime::dayOfWeek (_tokens[1])) != -1)
{
Datetime start (range.start.year (), range.start.month (), range.start.day (), 0, 0, 0);
while (start <= range.end)
Range myRange = {range};
if (myRange.is_open())
{
myRange.end = Datetime("tomorrow");
}
while (start <= myRange.end)
{
if (start.dayOfWeek () == dayOfWeek)
{
@ -132,7 +140,7 @@ std::vector <Range> Exclusion::ranges (const Range& range) const
for (unsigned int block = 2; block < _tokens.size (); ++block)
{
auto r = rangeFromTimeBlock (_tokens[block], start, end);
if (range.overlap (r))
if (myRange.overlap (r))
results.push_back (r);
}
}

View file

@ -50,12 +50,32 @@ int CmdDelete (
Interval filter;
auto tracked = getTracked (database, rules, filter);
// Apply tags to ids.
bool dirty = true;
for (auto& id : ids)
{
if (id > static_cast <int> (tracked.size ()))
throw format ("ID '@{1}' does not correspond to any tracking.", id);
if (tracked[tracked.size() - id].synthetic && dirty)
{
auto latest = getLatestInterval(database);
auto exclusions = getAllExclusions (rules, filter.range);
Interval modified {latest};
// Update database.
database.deleteInterval (latest);
for (auto& interval : flatten (modified, exclusions))
database.addInterval (interval);
dirty = false;
}
}
// Delete intervals by id
for (auto& id : ids)
{
database.deleteInterval (tracked[tracked.size () - id]);
if (rules.getBoolean ("verbose"))