From fef522c53d3b929803efdc16fac1250439285094 Mon Sep 17 00:00:00 2001 From: Janik Rabe Date: Sun, 26 Aug 2018 11:50:35 +0200 Subject: [PATCH] Fix getTracked() when last interval is empty --- src/data.cpp | 14 ++++++-------- test/ids.t | 10 ++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/data.cpp b/src/data.cpp index 0dd26d4a..ea5f1def 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -595,9 +595,9 @@ std::vector getTracked ( auto inclusions = getAllInclusions (database); // Exclusions are only usable within a range, so if no filter range exists, - // determine the outermost range of the inclusions, ie: + // determine the infinite range starting at the first inclusion, i.e.: // - // [earliest start, latest end) + // [earliest start, infinity) // // Avoid assigning a zero-width range - leave it unstarted instead. if (! filter.range.is_started ()) @@ -606,12 +606,10 @@ std::vector getTracked ( if (outer.total ()) filter.range = outer; - if (! inclusions.empty ()) { - auto latest = inclusions.back(); - if (latest.range.is_open()) { - filter.range.end = 0; - } - } + // Use an infinite range instead of the last end date; this prevents + // issues when there is an empty range [q, q) at the end of a filter + // [p, q), in which case there is no overlap or intersection. + filter.range.end = 0; } std::vector intervals = inclusions; diff --git a/test/ids.t b/test/ids.t index db27852a..ebd0f8f7 100755 --- a/test/ids.t +++ b/test/ids.t @@ -48,6 +48,16 @@ class TestIds(TestCase): self.assertIn(' @1 ', out) self.assertIn(' @2 ', out) + def test_latest_interval_included_when_empty(self): + """Count IDs when the last interval is empty + Include the last interval in getTracked() even if it is a + zero-width interval and there are other, earlier intervals. + """ + self.t("track 2018-01-01 - 2018-01-01") + self.t("track 2018-01-02 - 2018-01-02") + code, out, err = self.t("move @2 2018-01-03") + self.assertIn('Moved @2 to 2018-01-03T00:00:00', out) + def test_should_fail_on_zero_id(self): code, out, err = self.t.runError("delete @0") self.assertIn("'@0' is not a valid ID.", err)