Skip to content

Commit 61f1566

Browse files
committedMay 8, 2020
Optimise comparison of date/time/datetime values in expressions
Avoid forced conversion to string when comparing the same date/time types
1 parent e9bc483 commit 61f1566

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
 

‎src/core/expression/qgsexpressionnodeimpl.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,30 @@ QVariant QgsExpressionNodeBinaryOperator::evalNode( QgsExpression *parent, const
403403
return TVL_Unknown;
404404
}
405405
}
406+
else if ( ( vL.type() == QVariant::DateTime && vR.type() == QVariant::DateTime ) )
407+
{
408+
const QDateTime dL = QgsExpressionUtils::getDateTimeValue( vL, parent );
409+
ENSURE_NO_EVAL_ERROR;
410+
const QDateTime dR = QgsExpressionUtils::getDateTimeValue( vR, parent );
411+
ENSURE_NO_EVAL_ERROR;
412+
return compare( dR.msecsTo( dL ) ) ? TVL_True : TVL_False;
413+
}
414+
else if ( ( vL.type() == QVariant::Date && vR.type() == QVariant::Date ) )
415+
{
416+
const QDate dL = QgsExpressionUtils::getDateValue( vL, parent );
417+
ENSURE_NO_EVAL_ERROR;
418+
const QDate dR = QgsExpressionUtils::getDateValue( vR, parent );
419+
ENSURE_NO_EVAL_ERROR;
420+
return compare( dR.daysTo( dL ) ) ? TVL_True : TVL_False;
421+
}
422+
else if ( ( vL.type() == QVariant::Time && vR.type() == QVariant::Time ) )
423+
{
424+
const QTime dL = QgsExpressionUtils::getTimeValue( vL, parent );
425+
ENSURE_NO_EVAL_ERROR;
426+
const QTime dR = QgsExpressionUtils::getTimeValue( vR, parent );
427+
ENSURE_NO_EVAL_ERROR;
428+
return compare( dR.msecsTo( dL ) ) ? TVL_True : TVL_False;
429+
}
406430
else if ( ( vL.type() != QVariant::String || vR.type() != QVariant::String ) &&
407431
QgsExpressionUtils::isDoubleSafe( vL ) && QgsExpressionUtils::isDoubleSafe( vR ) )
408432
{

0 commit comments

Comments
 (0)
Please sign in to comment.