diff --git a/app/common/timerange.cpp b/app/common/timerange.cpp index 440066b7d..78df8b438 100644 --- a/app/common/timerange.cpp +++ b/app/common/timerange.cpp @@ -48,6 +48,27 @@ bool TimeRange::operator==(const TimeRange &r) const return in() == r.in() && out() == r.out(); } +bool TimeRange::OverlapsWith(const TimeRange &a) const +{ + return Overlap(a, *this); +} + +TimeRange TimeRange::CombineWith(const TimeRange &a) const +{ + return Combine(a, *this); +} + +bool TimeRange::Overlap(const TimeRange &a, const TimeRange &b) +{ + return !(a.out() < b.in() || a.in() > b.out()); +} + +TimeRange TimeRange::Combine(const TimeRange &a, const TimeRange &b) +{ + return TimeRange(qMin(a.in(), b.in()), + qMax(a.out(), b.out())); +} + void TimeRange::normalize() { // If `out` is earlier than `in`, swap them diff --git a/app/common/timerange.h b/app/common/timerange.h index 26658c25c..fa239baed 100644 --- a/app/common/timerange.h +++ b/app/common/timerange.h @@ -18,6 +18,12 @@ public: bool operator==(const TimeRange& r) const; + bool OverlapsWith(const TimeRange& a) const; + TimeRange CombineWith(const TimeRange& a) const; + + static bool Overlap(const TimeRange& a, const TimeRange& b); + static TimeRange Combine(const TimeRange &a, const TimeRange &b); + private: void normalize();