QGIS API Documentation 3.41.0-Master (25ec5511245)
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
QgsInterval Class Reference

A representation of the interval between two datetime values. More...

#include <qgsinterval.h>

Public Member Functions

 QgsInterval ()=default
 Default constructor for QgsInterval.
 
 QgsInterval (double duration, Qgis::TemporalUnit unit)
 Constructor for QgsInterval, using the specified duration and units.
 
 QgsInterval (double seconds)
 Constructor for QgsInterval.
 
 QgsInterval (double years, double months, double weeks, double days, double hours, double minutes, double seconds)
 Constructor for QgsInterval, using the specified years, months, weeks, days, hours, minutes and seconds.
 
 QgsInterval (std::chrono::milliseconds milliseconds)
 Constructor for QgsInterval.
 
double days () const
 Returns the interval duration in days.
 
double hours () const
 Returns the interval duration in hours.
 
bool isValid () const
 Returns true if the interval is valid.
 
double minutes () const
 Returns the interval duration in minutes.
 
double months () const
 Returns the interval duration in months (based on a 30 day month).
 
 operator QVariant () const
 Allows direct construction of QVariants from intervals.
 
bool operator!= (QgsInterval other) const
 
bool operator== (QgsInterval other) const
 
double originalDuration () const
 Returns the original interval duration.
 
Qgis::TemporalUnit originalUnit () const
 Returns the original interval temporal unit.
 
double seconds () const
 Returns the interval duration in seconds.
 
void setDays (double days)
 Sets the interval duration in days.
 
void setHours (double hours)
 Sets the interval duration in hours.
 
void setMinutes (double minutes)
 Sets the interval duration in minutes.
 
void setMonths (double months)
 Sets the interval duration in months.
 
void setSeconds (double seconds)
 Sets the interval duration in seconds.
 
void setValid (bool valid)
 Sets whether the interval is valid.
 
void setWeeks (double weeks)
 Sets the interval duration in weeks.
 
void setYears (double years)
 Sets the interval duration in years.
 
double weeks () const
 Returns the interval duration in weeks.
 
double years () const
 Returns the interval duration in years (based on an average year length)
 

Static Public Member Functions

static QgsInterval fromString (const QString &string)
 Converts a string to an interval.
 

Static Public Attributes

static const int DAY = 60 * 60 * 24
 Seconds per day.
 
static const int HOUR = 60 * 60
 Seconds per hour.
 
static const int MINUTE = 60
 Seconds per minute.
 
static const int MONTHS = 60 * 60 * 24 * 30
 Seconds per month, based on 30 day month.
 
static const int WEEKS = 60 * 60 * 24 * 7
 Seconds per week.
 
static const int YEARS = 31557600
 Seconds per year (average)
 

Detailed Description

A representation of the interval between two datetime values.

Definition at line 45 of file qgsinterval.h.

Constructor & Destructor Documentation

◆ QgsInterval() [1/5]

QgsInterval::QgsInterval ( )
default

Default constructor for QgsInterval.

Creates an invalid interval.

◆ QgsInterval() [2/5]

QgsInterval::QgsInterval ( double  seconds)

Constructor for QgsInterval.

Parameters
secondsduration of interval in seconds

Definition at line 33 of file qgsinterval.cpp.

◆ QgsInterval() [3/5]

QgsInterval::QgsInterval ( std::chrono::milliseconds  milliseconds)

Constructor for QgsInterval.

Parameters
millisecondsduration of interval in milliseconds

Definition at line 41 of file qgsinterval.cpp.

◆ QgsInterval() [4/5]

QgsInterval::QgsInterval ( double  duration,
Qgis::TemporalUnit  unit 
)

Constructor for QgsInterval, using the specified duration and units.

Definition at line 49 of file qgsinterval.cpp.

◆ QgsInterval() [5/5]

QgsInterval::QgsInterval ( double  years,
double  months,
double  weeks,
double  days,
double  hours,
double  minutes,
double  seconds 
)

Constructor for QgsInterval, using the specified years, months, weeks, days, hours, minutes and seconds.

Note
Month units assumes a 30 day month length.
Year units assumes a 365.25 day year length.
Since
QGIS 3.14

Definition at line 57 of file qgsinterval.cpp.

Member Function Documentation

◆ days()

double QgsInterval::days ( ) const

Returns the interval duration in days.

If the originalUnit() is QgsUnitTypes::TemporalDays then this value will match the exact number of days as returned by originalDuration(), otherwise it will be calculated using the QgsInterval::DAY constant.

See also
setDays()

Definition at line 162 of file qgsinterval.cpp.

◆ fromString()

QgsInterval QgsInterval::fromString ( const QString &  string)
static

Converts a string to an interval.

Parameters
stringstring to parse
Returns
interval, or invalid interval if string could not be parsed

Definition at line 220 of file qgsinterval.cpp.

◆ hours()

double QgsInterval::hours ( ) const

Returns the interval duration in hours.

If the originalUnit() is QgsUnitTypes::TemporalHours then this value will match the exact number of hours as returned by originalDuration(), otherwise it will be calculated using the QgsInterval::HOUR constant.

See also
setHours()

Definition at line 179 of file qgsinterval.cpp.

◆ isValid()

bool QgsInterval::isValid ( ) const
inline

Returns true if the interval is valid.

See also
setValid()

Definition at line 279 of file qgsinterval.h.

◆ minutes()

double QgsInterval::minutes ( ) const

Returns the interval duration in minutes.

If the originalUnit() is QgsUnitTypes::TemporalMinutes then this value will match the exact number of minutes as returned by originalDuration(), otherwise it will be calculated using the QgsInterval::MINUTE constant.

See also
setMinutes()

Definition at line 196 of file qgsinterval.cpp.

◆ months()

double QgsInterval::months ( ) const

Returns the interval duration in months (based on a 30 day month).

If the originalUnit() is QgsUnitTypes::TemporalMonths then this value will match the exact number of months as returned by originalDuration(), otherwise it will be calculated using the assumption that a month consists of exactly 30 days.

See also
setMonths()

Definition at line 129 of file qgsinterval.cpp.

◆ operator QVariant()

QgsInterval::operator QVariant ( ) const
inline

Allows direct construction of QVariants from intervals.

Definition at line 346 of file qgsinterval.h.

◆ operator!=()

bool QgsInterval::operator!= ( QgsInterval  other) const
inline

Definition at line 333 of file qgsinterval.h.

◆ operator==()

bool QgsInterval::operator== ( QgsInterval  other) const
inline

Definition at line 321 of file qgsinterval.h.

◆ originalDuration()

double QgsInterval::originalDuration ( ) const
inline

Returns the original interval duration.

This original interval duration can be updated through calling QgsInterval setter methods.

See also
originalUnit() for the corresponding unit.

If the original interval duration is not available or interval was set with a mix of units, calling originalUnit() will return QgsUnitTypes::TemporalUnknownUnit

Returns 0.0 if the original duration was not set.

Since
QGIS 3.18

Definition at line 304 of file qgsinterval.h.

◆ originalUnit()

Qgis::TemporalUnit QgsInterval::originalUnit ( ) const
inline

Returns the original interval temporal unit.

The interval temporal unit can be set through the QgsInterval constructors or through the available setter methods.

Returns QgsUnitTypes::TemporalUnknownUnit if unit was not set when creating the QgsInterval instance or interval was set with a mix of units.

See also
originalDuration()
Since
QGIS 3.18

Definition at line 319 of file qgsinterval.h.

◆ seconds()

double QgsInterval::seconds ( ) const
inline

Returns the interval duration in seconds.

See also
setSeconds()

Definition at line 260 of file qgsinterval.h.

◆ setDays()

void QgsInterval::setDays ( double  days)

Sets the interval duration in days.

Replaces the interval size and changes the original interval unit and duration,

See also
originalDuration() and
originalUnit().

Changes the original unit to QgsUnitTypes::TemporalDays

Parameters
daysduration in days
See also
days()

Definition at line 171 of file qgsinterval.cpp.

◆ setHours()

void QgsInterval::setHours ( double  hours)

Sets the interval duration in hours.

Replaces the interval size and changes the original interval unit and duration,

See also
originalDuration() and
originalUnit().

The original unit to QgsUnitTypes::TemporalHours

Parameters
hoursduration in hours
See also
hours()

Definition at line 188 of file qgsinterval.cpp.

◆ setMinutes()

void QgsInterval::setMinutes ( double  minutes)

Sets the interval duration in minutes.

Replaces the interval size and changes the original interval unit and duration,

See also
originalDuration() and
originalUnit().

Changes the original unit to QgsUnitTypes::TemporalMinutes

Parameters
minutesduration in minutes
See also
minutes()

Definition at line 204 of file qgsinterval.cpp.

◆ setMonths()

void QgsInterval::setMonths ( double  months)

Sets the interval duration in months.

Replaces the interval size and changes the original interval unit and duration,

See also
originalDuration() and
originalUnit().

Changes the original unit to QgsUnitTypes::TemporalMonths

Parameters
monthsduration in months (based on a 30 day month)
See also
months()

Definition at line 137 of file qgsinterval.cpp.

◆ setSeconds()

void QgsInterval::setSeconds ( double  seconds)

Sets the interval duration in seconds.

Replaces the interval size and changes the original interval unit and duration,

See also
originalDuration() and
originalUnit().

Changes the original unit to QgsUnitTypes::TemporalSeconds

Parameters
secondsduration in seconds
See also
seconds()

Definition at line 212 of file qgsinterval.cpp.

◆ setValid()

void QgsInterval::setValid ( bool  valid)
inline

Sets whether the interval is valid.

Parameters
validset to true to set the interval as valid.
See also
isValid()

Definition at line 286 of file qgsinterval.h.

◆ setWeeks()

void QgsInterval::setWeeks ( double  weeks)

Sets the interval duration in weeks.

Replaces the interval size and changes the original interval unit and duration,

See also
originalDuration() and
originalUnit().

Changes the original unit to QgsUnitTypes::TemporalWeeks

Parameters
weeksduration in weeks
See also
weeks()

Definition at line 154 of file qgsinterval.cpp.

◆ setYears()

void QgsInterval::setYears ( double  years)

Sets the interval duration in years.

Replaces the interval size and changes the original interval unit and duration,

See also
originalDuration() and
originalUnit().

Changes the original unit to QgsUnitTypes::TemporalYears

Parameters
yearsduration in years (based on average year length)
See also
years()

Definition at line 121 of file qgsinterval.cpp.

◆ weeks()

double QgsInterval::weeks ( ) const

Returns the interval duration in weeks.

If the originalUnit() is QgsUnitTypes::TemporalWeeks then this value will match the exact number of weeks as returned by originalDuration(), otherwise it will be calculated using the QgsInterval::WEEKS constant.

See also
setWeeks()

Definition at line 145 of file qgsinterval.cpp.

◆ years()

double QgsInterval::years ( ) const

Returns the interval duration in years (based on an average year length)

If the originalUnit() is QgsUnitTypes::TemporalYears then this value will match the exact number of months as returned by originalDuration(), otherwise it will be calculated using the average year length (31557600 seconds).

See also
setYears()

Definition at line 113 of file qgsinterval.cpp.

Member Data Documentation

◆ DAY

const int QgsInterval::DAY = 60 * 60 * 24
static

Seconds per day.

Definition at line 58 of file qgsinterval.h.

◆ HOUR

const int QgsInterval::HOUR = 60 * 60
static

Seconds per hour.

Definition at line 60 of file qgsinterval.h.

◆ MINUTE

const int QgsInterval::MINUTE = 60
static

Seconds per minute.

Definition at line 62 of file qgsinterval.h.

◆ MONTHS

const int QgsInterval::MONTHS = 60 * 60 * 24 * 30
static

Seconds per month, based on 30 day month.

Definition at line 54 of file qgsinterval.h.

◆ WEEKS

const int QgsInterval::WEEKS = 60 * 60 * 24 * 7
static

Seconds per week.

Definition at line 56 of file qgsinterval.h.

◆ YEARS

const int QgsInterval::YEARS = 31557600
static

Seconds per year (average)

Definition at line 52 of file qgsinterval.h.


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