Skip to content
Permalink
Browse files

Optimise comparison of date/time/datetime values in expressions

Avoid forced conversion to string when comparing the same date/time
types
  • Loading branch information
nyalldawson committed May 7, 2020
1 parent e9bc483 commit 61f1566285a36073a883eb4681dc5d05d1e1b5f2
Showing with 24 additions and 0 deletions.
  1. +24 −0 src/core/expression/qgsexpressionnodeimpl.cpp
@@ -403,6 +403,30 @@ QVariant QgsExpressionNodeBinaryOperator::evalNode( QgsExpression *parent, const
return TVL_Unknown;
}
}
else if ( ( vL.type() == QVariant::DateTime && vR.type() == QVariant::DateTime ) )
{
const QDateTime dL = QgsExpressionUtils::getDateTimeValue( vL, parent );
ENSURE_NO_EVAL_ERROR;
const QDateTime dR = QgsExpressionUtils::getDateTimeValue( vR, parent );
ENSURE_NO_EVAL_ERROR;
return compare( dR.msecsTo( dL ) ) ? TVL_True : TVL_False;
}
else if ( ( vL.type() == QVariant::Date && vR.type() == QVariant::Date ) )
{
const QDate dL = QgsExpressionUtils::getDateValue( vL, parent );
ENSURE_NO_EVAL_ERROR;
const QDate dR = QgsExpressionUtils::getDateValue( vR, parent );
ENSURE_NO_EVAL_ERROR;
return compare( dR.daysTo( dL ) ) ? TVL_True : TVL_False;
}
else if ( ( vL.type() == QVariant::Time && vR.type() == QVariant::Time ) )
{
const QTime dL = QgsExpressionUtils::getTimeValue( vL, parent );
ENSURE_NO_EVAL_ERROR;
const QTime dR = QgsExpressionUtils::getTimeValue( vR, parent );
ENSURE_NO_EVAL_ERROR;
return compare( dR.msecsTo( dL ) ) ? TVL_True : TVL_False;
}
else if ( ( vL.type() != QVariant::String || vR.type() != QVariant::String ) &&
QgsExpressionUtils::isDoubleSafe( vL ) && QgsExpressionUtils::isDoubleSafe( vR ) )
{

0 comments on commit 61f1566

Please sign in to comment.
You can’t perform that action at this time.