diff --git a/src/lib/time/timevalue.hpp b/src/lib/time/timevalue.hpp index aa08c00ca..4087a9f5f 100644 --- a/src/lib/time/timevalue.hpp +++ b/src/lib/time/timevalue.hpp @@ -409,8 +409,14 @@ namespace time { Time end() const { - TimeVar startPoint (*this); - return (startPoint + dur_); + return TimeVar(*this) += dur_; + } + + bool + contains (TimeValue const& tp) const + { + return *this <= tp + && tp < end(); } /** may change start / duration */ diff --git a/tests/lib/time/time-value-test.cpp b/tests/lib/time/time-value-test.cpp index 27c4c1524..9a5a6fc4c 100644 --- a/tests/lib/time/time-value-test.cpp +++ b/tests/lib/time/time-value-test.cpp @@ -75,6 +75,7 @@ namespace test{ buildDuration (ref); buildTimeSpan (ref); compareTimeSpan (ref); + relateTimeIntervals (ref); } @@ -381,6 +382,30 @@ namespace test{ CHECK (span3y.end() < span3z.end()); CHECK (Time(span3) < Time(span3z)); } + + + void + relateTimeIntervals (TimeValue org) + { + TimeSpan span1 (org, FSecs(2)); + TimeSpan span2 (org+Time(FSecs(1)), FSecs(2)); + + TimeVar probe(org); + CHECK ( span1.contains(probe)); + CHECK (!span2.contains(probe)); + + probe = span2; + CHECK ( span1.contains(probe)); + CHECK ( span2.contains(probe)); + + probe = span1.end(); + CHECK (!span1.contains(probe)); // Note: end is always exclusive + CHECK ( span2.contains(probe)); + + probe = span2.end(); + CHECK (!span1.contains(probe)); + CHECK (!span2.contains(probe)); + } };