Class: QgsInterval¶
A representation of the interval between two datetime values.
Methods
Returns the interval duration in days. |
|
Returns the interval duration in hours. |
|
Returns |
|
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) |
Static Methods
Converts a string to an interval |
Attributes
Seconds per day |
|
Seconds per hour |
|
Seconds per minute |
|
Seconds per month, based on 30 day month |
|
Seconds per week |
|
Seconds per year (average) |
- class qgis.core.QgsInterval[source]¶
Bases:
object
- __init__()
Default constructor for QgsInterval. Creates an invalid interval.
- __init__(seconds: float)
Constructor for QgsInterval.
- Parameters:
seconds (float) – duration of interval in seconds
- __init__(duration: float, unit: Qgis.TemporalUnit)
Constructor for QgsInterval, using the specified
duration
andunits
.- Parameters:
duration (float)
unit (Qgis.TemporalUnit)
- __init__(years: float, months: float, weeks: float, days: float, hours: float, minutes: float, seconds: float)
Constructor for QgsInterval, using the specified
years
,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.
Added in version 3.14.
- Parameters:
years (float)
months (float)
weeks (float)
days (float)
hours (float)
minutes (float)
seconds (float)
- __init__(a0: QgsInterval)
- Parameters:
a0 (QgsInterval)
- DAY: int = 86400¶
Seconds per day
- HOUR: int = 3600¶
Seconds per hour
- MINUTE: int = 60¶
Seconds per minute
- MONTHS: int = 2592000¶
Seconds per month, based on 30 day month
- WEEKS: int = 604800¶
Seconds per week
- YEARS: int = 31557600¶
Seconds per year (average)
- days(self) float [source]¶
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
- static fromString(string: str | None) QgsInterval [source]¶
Converts a string to an interval
- Parameters:
string (Optional[str]) – string to parse
- Return type:
- Returns:
interval, or invalid interval if string could not be parsed
- hours(self) float [source]¶
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
- minutes(self) float [source]¶
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 [source]¶
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 [source]¶
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 returnQgsUnitTypes
.TemporalUnknownUnitReturns 0.0 if the original duration was not set.
Added in version 3.18.
- Return type:
float
- originalUnit(self) Qgis.TemporalUnit [source]¶
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
Added in version 3.18.
- Return type:
- setDays(self, days: float)[source]¶
Sets the interval duration in days.
Replaces the interval size and changes the original interval unit and duration,
originalDuration()
andoriginalUnit()
.Changes the original unit to
QgsUnitTypes
.TemporalDays- Parameters:
days (float) – duration in days
See also
- setHours(self, hours: float)[source]¶
Sets the interval duration in hours.
Replaces the interval size and changes the original interval unit and duration,
originalDuration()
andoriginalUnit()
.The original unit to
QgsUnitTypes
.TemporalHours- Parameters:
hours (float) – duration in hours
See also
- setMinutes(self, minutes: float)[source]¶
Sets the interval duration in minutes.
Replaces the interval size and changes the original interval unit and duration,
originalDuration()
andoriginalUnit()
.Changes the original unit to
QgsUnitTypes
.TemporalMinutes- Parameters:
minutes (float) – duration in minutes
See also
- setMonths(self, months: float)[source]¶
Sets the interval duration in months.
Replaces the interval size and changes the original interval unit and duration,
originalDuration()
andoriginalUnit()
.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)[source]¶
Sets the interval duration in seconds.
Replaces the interval size and changes the original interval unit and duration,
originalDuration()
andoriginalUnit()
.Changes the original unit to
QgsUnitTypes
.TemporalSeconds- Parameters:
seconds (float) – duration in seconds
See also
- setValid(self, valid: bool)[source]¶
Sets whether the interval is valid.
- Parameters:
valid (bool) – set to
True
to set the interval as valid.
See also
- setWeeks(self, weeks: float)[source]¶
Sets the interval duration in weeks.
Replaces the interval size and changes the original interval unit and duration,
originalDuration()
andoriginalUnit()
.Changes the original unit to
QgsUnitTypes
.TemporalWeeks- Parameters:
weeks (float) – duration in weeks
See also
- setYears(self, years: float)[source]¶
Sets the interval duration in years.
Replaces the interval size and changes the original interval unit and duration,
originalDuration()
andoriginalUnit()
.Changes the original unit to
QgsUnitTypes
.TemporalYears- Parameters:
years (float) – duration in years (based on average year length)
See also
- weeks(self) float [source]¶
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 [source]¶
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