QGIS API Documentation  3.20.0-Odense (decaadbb31)
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. More...
 
 QgsInterval (double duration, QgsUnitTypes::TemporalUnit unit)
 Constructor for QgsInterval, using the specified duration and units. More...
 
 QgsInterval (double seconds)
 Constructor for QgsInterval. More...
 
 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. More...
 
double days () const
 Returns the interval duration in days. More...
 
double hours () const
 Returns the interval duration in hours. More...
 
bool isValid () const
 Returns true if the interval is valid. More...
 
double minutes () const
 Returns the interval duration in minutes. More...
 
double months () const
 Returns the interval duration in months (based on a 30 day month). More...
 
 operator QVariant () const
 Allows direct construction of QVariants from intervals. More...
 
bool operator!= (QgsInterval other) const
 
bool operator== (QgsInterval other) const
 
double originalDuration () const
 Returns the original interval duration. More...
 
QgsUnitTypes::TemporalUnit originalUnit () const
 Returns the original interval temporal unit. More...
 
double seconds () const
 Returns the interval duration in seconds. More...
 
void setDays (double days)
 Sets the interval duration in days. More...
 
void setHours (double hours)
 Sets the interval duration in hours. More...
 
void setMinutes (double minutes)
 Sets the interval duration in minutes. More...
 
void setMonths (double months)
 Sets the interval duration in months. More...
 
void setSeconds (double seconds)
 Sets the interval duration in seconds. More...
 
void setValid (bool valid)
 Sets whether the interval is valid. More...
 
void setWeeks (double weeks)
 Sets the interval duration in weeks. More...
 
void setYears (double years)
 Sets the interval duration in years. More...
 
double weeks () const
 Returns the interval duration in weeks. More...
 
double years () const
 Returns the interval duration in years (based on an average year length) More...
 

Static Public Member Functions

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

Static Public Attributes

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

Detailed Description

A representation of the interval between two datetime values.

Since
QGIS 2.16

Definition at line 41 of file qgsinterval.h.

Constructor & Destructor Documentation

◆ QgsInterval() [1/4]

QgsInterval::QgsInterval ( )
default

Default constructor for QgsInterval.

Creates an invalid interval.

◆ QgsInterval() [2/4]

QgsInterval::QgsInterval ( double  seconds)

Constructor for QgsInterval.

Parameters
secondsduration of interval in seconds

Definition at line 30 of file qgsinterval.cpp.

◆ QgsInterval() [3/4]

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

Constructor for QgsInterval, using the specified duration and units.

Definition at line 38 of file qgsinterval.cpp.

◆ QgsInterval() [4/4]

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 46 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 151 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 209 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 168 of file qgsinterval.cpp.

◆ isValid()

bool QgsInterval::isValid ( ) const
inline

Returns true if the interval is valid.

See also
setValid()

Definition at line 255 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 185 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 118 of file qgsinterval.cpp.

◆ operator QVariant()

QgsInterval::operator QVariant ( ) const
inline

Allows direct construction of QVariants from intervals.

Definition at line 322 of file qgsinterval.h.

◆ operator!=()

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

Definition at line 309 of file qgsinterval.h.

◆ operator==()

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

Definition at line 297 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
3.18

Definition at line 280 of file qgsinterval.h.

◆ originalUnit()

QgsUnitTypes::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
3.18

Definition at line 295 of file qgsinterval.h.

◆ seconds()

double QgsInterval::seconds ( ) const
inline

Returns the interval duration in seconds.

See also
setSeconds()

Definition at line 236 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 160 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 177 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 193 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 126 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 201 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 262 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 143 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 110 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 134 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 102 of file qgsinterval.cpp.

Member Data Documentation

◆ DAY

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

Seconds per day.

Definition at line 54 of file qgsinterval.h.

◆ HOUR

const int QgsInterval::HOUR = 60 * 60
static

Seconds per hour.

Definition at line 56 of file qgsinterval.h.

◆ MINUTE

const int QgsInterval::MINUTE = 60
static

Seconds per minute.

Definition at line 58 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 50 of file qgsinterval.h.

◆ WEEKS

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

Seconds per week.

Definition at line 52 of file qgsinterval.h.

◆ YEARS

const int QgsInterval::YEARS = 31557600
static

Seconds per year (average)

Definition at line 48 of file qgsinterval.h.


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