Class: QgsInterval¶
- class qgis.core.QgsInterval¶
Bases:
sip.wrapper
A representation of the interval between two datetime values.
New in version 2.16.
QgsInterval() Default constructor for
QgsInterval
. Creates an invalid interval.QgsInterval(seconds: float) Constructor for QgsInterval.
- Parameters:
seconds – duration of interval in seconds
QgsInterval(duration: float, unit: QgsUnitTypes.TemporalUnit) Constructor for
QgsInterval
, using the specifiedduration
andunits
.QgsInterval(years: float, months: float, weeks: float, days: float, hours: float, minutes: float, seconds: float) Constructor for
QgsInterval
, using the specifiedyears
,months
,weeks
,days
,hours
,minutes
andseconds
.Note
Month units assumes a 30 day month length.
Note
Year units assumes a 365.25 day year length.
New in version 3.14.
QgsInterval(
QgsInterval
)Methods
Returns the interval duration in days.
Converts a string to an interval
Returns the interval duration in hours.
Returns
True
if the interval is valid.Returns the interval duration in minutes.
Returns the interval duration in months (based on a 30 day month).
Returns the original interval duration.
Returns the original interval temporal unit.
Returns the interval duration in seconds.
Sets the interval duration in days.
Sets the interval duration in hours.
Sets the interval duration in minutes.
Sets the interval duration in months.
Sets the interval duration in seconds.
Sets whether the interval is valid.
Sets the interval duration in weeks.
Sets the interval duration in years.
Returns the interval duration in weeks.
Returns the interval duration in years (based on an average year length)
Attributes
- DAY = 86400¶
- HOUR = 3600¶
- MINUTE = 60¶
- MONTHS = 2592000¶
- WEEKS = 604800¶
- YEARS = 31557600¶
- days(self) float ¶
Returns the interval duration in days.
If the
originalUnit()
isQgsUnitTypes
.TemporalDays then this value will match the exact number of days as returned byoriginalDuration()
, otherwise it will be calculated using the QgsInterval.DAY constant.See also
- Return type:
float
- fromString(string: str) QgsInterval ¶
Converts a string to an interval
- Parameters:
string (str) – string to parse
- Return type:
- Returns:
interval, or invalid interval if string could not be parsed
- hours(self) float ¶
Returns the interval duration in hours.
If the
originalUnit()
isQgsUnitTypes
.TemporalHours then this value will match the exact number of hours as returned byoriginalDuration()
, otherwise it will be calculated using the QgsInterval.HOUR constant.See also
- Return type:
float
- isValid(self) bool ¶
Returns
True
if the interval is valid.See also
- Return type:
bool
- minutes(self) float ¶
Returns the interval duration in minutes.
If the
originalUnit()
isQgsUnitTypes
.TemporalMinutes then this value will match the exact number of minutes as returned byoriginalDuration()
, otherwise it will be calculated using the QgsInterval.MINUTE constant.See also
- Return type:
float
- months(self) float ¶
Returns the interval duration in months (based on a 30 day month).
If the
originalUnit()
isQgsUnitTypes
.TemporalMonths then this value will match the exact number of months as returned byoriginalDuration()
, otherwise it will be calculated using the assumption that a month consists of exactly 30 days.See also
- Return type:
float
- originalDuration(self) float ¶
Returns the original interval duration.
This original interval duration can be updated through calling
QgsInterval
setter methods.See also
If the original interval duration is not available or interval was set with a mix of units, calling
originalUnit()
will returnQgsUnitTypes
.TemporalUnknownUnitReturns 0.0 if the original duration was not set.
New in version 3.18.
- Return type:
float
- originalUnit(self) QgsUnitTypes.TemporalUnit ¶
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 theQgsInterval
instance or interval was set with a mix of units.See also
New in version 3.18.
- Return type:
- seconds(self) float ¶
Returns the interval duration in seconds.
See also
- Return type:
float
- setDays(self, days: float)¶
Sets the interval duration in days.
Replaces the interval size and changes the original interval unit and duration,
originalDuration()
and see originalUnit().Changes the original unit to
QgsUnitTypes
.TemporalDays- Parameters:
days (float) – duration in days
See also
- setHours(self, hours: float)¶
Sets the interval duration in hours.
Replaces the interval size and changes the original interval unit and duration,
originalDuration()
and see originalUnit().The original unit to
QgsUnitTypes
.TemporalHours- Parameters:
hours (float) – duration in hours
See also
- setMinutes(self, minutes: float)¶
Sets the interval duration in minutes.
Replaces the interval size and changes the original interval unit and duration,
originalDuration()
and see originalUnit().Changes the original unit to
QgsUnitTypes
.TemporalMinutes- Parameters:
minutes (float) – duration in minutes
See also
- setMonths(self, months: float)¶
Sets the interval duration in months.
Replaces the interval size and changes the original interval unit and duration,
originalDuration()
and see originalUnit().Changes the original unit to
QgsUnitTypes
.TemporalMonths- Parameters:
months (float) – duration in months (based on a 30 day month)
See also
- setSeconds(self, seconds: float)¶
Sets the interval duration in seconds.
Replaces the interval size and changes the original interval unit and duration,
originalDuration()
and see originalUnit().Changes the original unit to
QgsUnitTypes
.TemporalSeconds- Parameters:
seconds (float) – duration in seconds
See also
- setValid(self, valid: bool)¶
Sets whether the interval is valid.
- Parameters:
valid (bool) – set to
True
to set the interval as valid.
See also
- setWeeks(self, weeks: float)¶
Sets the interval duration in weeks.
Replaces the interval size and changes the original interval unit and duration,
originalDuration()
and see originalUnit().Changes the original unit to
QgsUnitTypes
.TemporalWeeks- Parameters:
weeks (float) – duration in weeks
See also
- setYears(self, years: float)¶
Sets the interval duration in years.
Replaces the interval size and changes the original interval unit and duration,
originalDuration()
and see originalUnit().Changes the original unit to
QgsUnitTypes
.TemporalYears- Parameters:
years (float) – duration in years (based on average year length)
See also
- weeks(self) float ¶
Returns the interval duration in weeks.
If the
originalUnit()
isQgsUnitTypes
.TemporalWeeks then this value will match the exact number of weeks as returned byoriginalDuration()
, otherwise it will be calculated using the QgsInterval.WEEKS constant.See also
- Return type:
float
- years(self) float ¶
Returns the interval duration in years (based on an average year length)
If the
originalUnit()
isQgsUnitTypes
.TemporalYears then this value will match the exact number of months as returned byoriginalDuration()
, otherwise it will be calculated using the average year length (31557600 seconds).See also
- Return type:
float