34using namespace Qt::StringLiterals;
57 static const int YEARS = 31557600;
59 static const int MONTHS = 60 * 60 * 24 * 30;
61 static const int WEEKS = 60 * 60 * 24 * 7;
63 static const int DAY = 60 * 60 * 24;
65 static const int HOUR = 60 * 60;
104 SIP_PYOBJECT __repr__();
107 if ( ! sipCpp->isValid() )
108 str = u
"<QgsInterval: invalid>"_s;
110 str = u
"<QgsInterval: %1 %2>"_s.arg( sipCpp->originalDuration() ).arg(
QgsUnitTypes::toString( sipCpp->originalUnit() ) );
112 str = u
"<QgsInterval: %1 seconds>"_s.arg( sipCpp->seconds() );
113 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
127 double years()
const;
176 double weeks()
const;
224 double hours()
const;
280 void setSeconds(
double seconds );
330 if ( !mValid && !other.mValid )
333 return mOriginalUnit == other.mOriginalUnit && mOriginalDuration == other.mOriginalDuration;
334 else if ( mValid && other.mValid )
347 static QgsInterval fromString(
const QString &
string );
350 operator QVariant()
const {
return QVariant::fromValue( *
this ); }
354 double mSeconds = 0.0;
360 double mOriginalDuration = 0.0;
TemporalUnit
Temporal units.
@ Unknown
Unknown time unit.
A representation of the interval between two datetime values.
static const int MINUTE
Seconds per minute.
double originalDuration() const
Returns the original interval duration.
bool isValid() const
Returns true if the interval is valid.
double days() const
Returns the interval duration in days.
void setMinutes(double minutes)
Sets the interval duration in minutes.
void setValid(bool valid)
Sets whether the interval is valid.
void setWeeks(double weeks)
Sets the interval duration in weeks.
QgsInterval()=default
Default constructor for QgsInterval.
double weeks() const
Returns the interval duration in weeks.
static const int MONTHS
Seconds per month, based on 30 day month.
double months() const
Returns the interval duration in months (based on a 30 day month).
bool operator==(QgsInterval other) const
double seconds() const
Returns the interval duration in seconds.
Qgis::TemporalUnit originalUnit() const
Returns the original interval temporal unit.
double years() const
Returns the interval duration in years (based on an average year length).
static const int HOUR
Seconds per hour.
static const int WEEKS
Seconds per week.
static const int DAY
Seconds per day.
double hours() const
Returns the interval duration in hours.
void setHours(double hours)
Sets the interval duration in hours.
bool operator!=(QgsInterval other) const
static const int YEARS
Seconds per year (average).
void setYears(double years)
Sets the interval duration in years.
void setDays(double days)
Sets the interval duration in days.
double minutes() const
Returns the interval duration in minutes.
void setMonths(double months)
Sets the interval duration in months.
static Q_INVOKABLE QString toString(Qgis::DistanceUnit unit)
Returns a translated string representing a distance unit.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QDateTime CORE_EXPORT operator+(const QDateTime &start, const QgsInterval &interval)
Adds an interval to a datetime.
QgsInterval CORE_EXPORT operator-(QDate date1, QDate date2)
Returns the interval between two dates.
QDebug CORE_EXPORT operator<<(QDebug dbg, const QgsInterval &interval)
Debug string representation of interval.