KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
TimeSpanRange Class Reference

An interval of time defined by a start TimeSpan offset and an end TimeSpan offset. More...

#include <timespanrange.h>

Classes

class  List
 A QList of TimeSpanRange objects with a consolidated() helper. More...
 

Public Member Functions

 TimeSpanRange ()
 Default constructor — creates an invalid (default-constructed) range.
 
 TimeSpanRange (const TimeSpan &startOffset, const TimeSpan &endOffset)
 Construct a range from explicit start and end offsets.
 
 TimeSpanRange (const QDateTime &startTime, const TimeSpan &duration)
 Construct a range from an absolute QDateTime start and a duration.
 
 TimeSpanRange (const TimeSpanRange &other)
 Copy constructor.
 
TimeSpanRangeoperator= (const TimeSpanRange &other)
 Copy assignment.
 
TimeSpanRange operator+ (const TimeSpan &other) const
 Shift both endpoints forward by a TimeSpan delta.
 
TimeSpanRange operator- (const TimeSpan &other) const
 Shift both endpoints backward by a TimeSpan delta.
 
void operator+= (const TimeSpan &other)
 Add-assign a TimeSpan delta to both endpoints.
 
void operator-= (const TimeSpan &other)
 Subtract-assign a TimeSpan delta from both endpoints.
 
bool operator== (const TimeSpanRange &other) const
 Equality comparison.
 
bool operator!= (const TimeSpanRange &other) const
 Inequality comparison.
 
TimeSpan startOffset () const
 Return the start offset.
 
void setStartOffset (const TimeSpan &value)
 Set the start offset.
 
TimeSpan endOffset () const
 Return the end offset.
 
void setEndOffset (const TimeSpan &value)
 Set the end offset.
 
TimeSpan duration () const
 Return the duration of this range (end − start).
 
TimeSpan midpoint () const
 Return the midpoint of this range.
 
bool contains (const TimeSpan &time) const
 Test whether a time offset falls within this range (inclusive).
 
bool contains (const TimeSpanRange &other) const
 Test whether another range is entirely contained within this one.
 
TimeSpanRange subRange (const TimeSpanRange &other) const
 Return the portion of another range that overlaps this range.
 
TimeSpanRange merged (const TimeSpanRange &other) const
 Return the union of this range and another, spanning both.
 
QString toString () const
 Format this range as a human-readable string.
 
bool isValid () const
 Return true if both endpoints are valid TimeSpan values.
 

Static Public Member Functions

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.
 
static TimeSpanRange fromStartAndDuration (const TimeSpan &startOffset, const TimeSpan &duration)
 Construct a range from a start offset and a duration.
 
static TimeSpanRange merged (const TimeSpanRange &a, const TimeSpanRange &b)
 Return the union of two ranges, spanning both.
 

Detailed Description

An interval of time defined by a start TimeSpan offset and an end TimeSpan offset.

Useful for windowing or slicing time-series data. All arithmetic operators shift both endpoints by the same delta. The inner List class provides consolidated() to merge overlapping or adjacent ranges into a minimal non-overlapping set.

Definition at line 18 of file timespanrange.h.

Constructor & Destructor Documentation

◆ TimeSpanRange() [1/4]

TimeSpanRange::TimeSpanRange ( )
inline

Default constructor — creates an invalid (default-constructed) range.

Definition at line 22 of file timespanrange.h.

◆ TimeSpanRange() [2/4]

TimeSpanRange::TimeSpanRange ( const TimeSpan startOffset,
const TimeSpan endOffset 
)
inline

Construct a range from explicit start and end offsets.

Parameters
startOffsetStart of the range
endOffsetEnd of the range

Definition at line 29 of file timespanrange.h.

◆ TimeSpanRange() [3/4]

TimeSpanRange::TimeSpanRange ( const QDateTime &  startTime,
const TimeSpan duration 
)
inline

Construct a range from an absolute QDateTime start and a duration.

Parameters
startTimeStart time (converted to a millisecond-epoch offset)
durationLength of the range

Definition at line 37 of file timespanrange.h.

◆ TimeSpanRange() [4/4]

TimeSpanRange::TimeSpanRange ( const TimeSpanRange other)

Copy constructor.

Parameters
otherRange to copy

Member Function Documentation

◆ contains() [1/2]

bool TimeSpanRange::contains ( const TimeSpan time) const
inline

Test whether a time offset falls within this range (inclusive).

Parameters
timeTimeSpan offset to test
Returns
true if startOffset ≤ time ≤ endOffset

Definition at line 156 of file timespanrange.h.

◆ contains() [2/2]

bool TimeSpanRange::contains ( const TimeSpanRange other) const
inline

Test whether another range is entirely contained within this one.

Parameters
otherRange to test
Returns
true if both endpoints of other lie within this range

Definition at line 163 of file timespanrange.h.

References contains(), endOffset(), and startOffset().

Referenced by contains().

◆ duration()

TimeSpan TimeSpanRange::duration ( ) const
inline

Return the duration of this range (end − start).

Returns
Duration TimeSpan

Definition at line 143 of file timespanrange.h.

◆ endOffset()

TimeSpan TimeSpanRange::endOffset ( ) const
inline

Return the end offset.

Returns
End TimeSpan

Definition at line 131 of file timespanrange.h.

Referenced by TimeSpanRange::List::consolidated(), and contains().

◆ fromDateRange()

static TimeSpanRange TimeSpanRange::fromDateRange ( const DateRange dateRange)
static

Construct a TimeSpanRange from a DateRange.

Parameters
dateRangeSource date range
Returns
Equivalent TimeSpanRange expressed as millisecond-epoch offsets

◆ fromMidpoint()

static TimeSpanRange TimeSpanRange::fromMidpoint ( const TimeSpan midpoint,
const TimeSpan duration 
)
static

Construct a range centred on a midpoint with a given total duration.

Parameters
midpointCentre of the range
durationTotal length of the range
Returns
TimeSpanRange spanning [midpoint − duration/2, midpoint + duration/2]

◆ fromStartAndDuration()

static TimeSpanRange TimeSpanRange::fromStartAndDuration ( const TimeSpan startOffset,
const TimeSpan duration 
)
static

Construct a range from a start offset and a duration.

Parameters
startOffsetStart of the range
durationLength of the range
Returns
TimeSpanRange spanning [startOffset, startOffset + duration]

◆ isValid()

bool TimeSpanRange::isValid ( ) const
inline

Return true if both endpoints are valid TimeSpan values.

Returns
true if start and end offsets are both valid

Definition at line 197 of file timespanrange.h.

◆ merged() [1/2]

static TimeSpanRange TimeSpanRange::merged ( const TimeSpanRange a,
const TimeSpanRange b 
)
inlinestatic

Return the union of two ranges, spanning both.

Parameters
aFirst range
bSecond range
Returns
Merged range

Definition at line 185 of file timespanrange.h.

References merged().

◆ merged() [2/2]

TimeSpanRange TimeSpanRange::merged ( const TimeSpanRange other) const

Return the union of this range and another, spanning both.

Parameters
otherRange to merge with
Returns
Merged range from the earlier start to the later end

Referenced by merged().

◆ midpoint()

TimeSpan TimeSpanRange::midpoint ( ) const
inline

Return the midpoint of this range.

Returns
Midpoint TimeSpan

Definition at line 149 of file timespanrange.h.

◆ operator!=()

bool TimeSpanRange::operator!= ( const TimeSpanRange other) const

Inequality comparison.

Parameters
otherRange to compare with
Returns
true if both ranges differ

◆ operator+()

TimeSpanRange TimeSpanRange::operator+ ( const TimeSpan other) const

Shift both endpoints forward by a TimeSpan delta.

Parameters
otherAmount to add to both endpoints
Returns
Shifted range

◆ operator+=()

void TimeSpanRange::operator+= ( const TimeSpan other)

Add-assign a TimeSpan delta to both endpoints.

Parameters
otherAmount to add

◆ operator-()

TimeSpanRange TimeSpanRange::operator- ( const TimeSpan other) const

Shift both endpoints backward by a TimeSpan delta.

Parameters
otherAmount to subtract from both endpoints
Returns
Shifted range

◆ operator-=()

void TimeSpanRange::operator-= ( const TimeSpan other)

Subtract-assign a TimeSpan delta from both endpoints.

Parameters
otherAmount to subtract

◆ operator=()

TimeSpanRange & TimeSpanRange::operator= ( const TimeSpanRange other)

Copy assignment.

Parameters
otherRange to copy
Returns
Reference to this range

◆ operator==()

bool TimeSpanRange::operator== ( const TimeSpanRange other) const

Equality comparison.

Parameters
otherRange to compare with
Returns
true if both ranges are equal

◆ setEndOffset()

void TimeSpanRange::setEndOffset ( const TimeSpan value)
inline

Set the end offset.

Parameters
valueNew end TimeSpan

Definition at line 137 of file timespanrange.h.

◆ setStartOffset()

void TimeSpanRange::setStartOffset ( const TimeSpan value)
inline

Set the start offset.

Parameters
valueNew start TimeSpan

Definition at line 125 of file timespanrange.h.

◆ startOffset()

TimeSpan TimeSpanRange::startOffset ( ) const
inline

Return the start offset.

Returns
Start TimeSpan

Definition at line 119 of file timespanrange.h.

Referenced by TimeSpanRange::List::consolidated(), and contains().

◆ subRange()

TimeSpanRange TimeSpanRange::subRange ( const TimeSpanRange other) const

Return the portion of another range that overlaps this range.

Parameters
otherRange to intersect with
Returns
Intersecting sub-range

◆ toString()

QString TimeSpanRange::toString ( ) const

Format this range as a human-readable string.

Returns
String representation of the range

The documentation for this class was generated from the following file: