6#include <Kanoop/timespan.h>
7#include "kanoopcommon.h"
30 _startOffset(startOffset), _endOffset(endOffset) {}
38 _startOffset(
TimeSpan::fromMilliseconds(startTime.toMSecsSinceEpoch())),
39 _endOffset(
TimeSpan::fromMilliseconds(startTime.toMSecsSinceEpoch()) + duration) {}
156 bool contains(
const TimeSpan& time)
const {
return time >= _startOffset && time <= _endOffset; }
197 bool isValid()
const {
return _startOffset.isValid() && _endOffset.isValid(); }
202 class List :
public QList<TimeSpanRange>
213 std::sort(sorted.begin(), sorted.end(), [](
const TimeSpanRange& a,
const TimeSpanRange& b) { return a.startOffset() < b.startOffset(); });
215 if(sorted.count() < 2) {
221 for (
int i = 1; i < size(); ++i) {
231 result.append(current);
235 result.append(current);
A time range defined by a start and end QDateTime.
A QList of TimeSpanRange objects with a consolidated() helper.
List consolidated() const
Merge overlapping or adjacent ranges into a minimal sorted non-overlapping list.
An interval of time defined by a start TimeSpan offset and an end TimeSpan offset.
TimeSpan startOffset() const
Return the start offset.
TimeSpanRange subRange(const TimeSpanRange &other) const
Return the portion of another range that overlaps this range.
static TimeSpanRange fromStartAndDuration(const TimeSpan &startOffset, const TimeSpan &duration)
Construct a range from a start offset and a duration.
TimeSpan midpoint() const
Return the midpoint of this range.
static TimeSpanRange merged(const TimeSpanRange &a, const TimeSpanRange &b)
Return the union of two ranges, spanning both.
bool contains(const TimeSpanRange &other) const
Test whether another range is entirely contained within this one.
void setStartOffset(const TimeSpan &value)
Set the start offset.
static TimeSpanRange fromMidpoint(const TimeSpan &midpoint, const TimeSpan &duration)
Construct a range centred on a midpoint with a given total duration.
static TimeSpanRange fromDateRange(const DateRange &dateRange)
Construct a TimeSpanRange from a DateRange.
QString toString() const
Format this range as a human-readable string.
TimeSpanRange(const TimeSpan &startOffset, const TimeSpan &endOffset)
Construct a range from explicit start and end offsets.
void operator+=(const TimeSpan &other)
Add-assign a TimeSpan delta to both endpoints.
TimeSpan endOffset() const
Return the end offset.
bool operator==(const TimeSpanRange &other) const
Equality comparison.
TimeSpan duration() const
Return the duration of this range (end − start).
void setEndOffset(const TimeSpan &value)
Set the end offset.
TimeSpanRange operator+(const TimeSpan &other) const
Shift both endpoints forward by a TimeSpan delta.
TimeSpanRange(const QDateTime &startTime, const TimeSpan &duration)
Construct a range from an absolute QDateTime start and a duration.
bool contains(const TimeSpan &time) const
Test whether a time offset falls within this range (inclusive).
TimeSpanRange(const TimeSpanRange &other)
Copy constructor.
TimeSpanRange & operator=(const TimeSpanRange &other)
Copy assignment.
TimeSpanRange operator-(const TimeSpan &other) const
Shift both endpoints backward by a TimeSpan delta.
void operator-=(const TimeSpan &other)
Subtract-assign a TimeSpan delta from both endpoints.
TimeSpanRange merged(const TimeSpanRange &other) const
Return the union of this range and another, spanning both.
bool isValid() const
Return true if both endpoints are valid TimeSpan values.
bool operator!=(const TimeSpanRange &other) const
Inequality comparison.
TimeSpanRange()
Default constructor — creates an invalid (default-constructed) range.